public Point intersects(Line line) {
Line holder = new Line(slope, yintercept);
double x;
double y;
if (Math.abs(slope - line.slope) < 0.0000000001) {
return null;
// because can't be parallel and if they don't intercept it has to return null
} else {
//no clue what to do here
y = (holder.slope*x+yintercept);
}
Point interception = new Point(x, y);
return interception;
我不知道如何计算x等于提前感谢帮助
答案 0 :(得分:0)
使用f(x)= m * x + c ...
试用此版本class LineIntersectException extends Exception
{
LineIntersectException(String message)
{
super(message);
}
}
public static Point intersect(Line line1, Line line2)
{
if(line1.m == line2.m)
{
throw new LineIntersectException("The two lines don't intersect");
}
double x = (line1.c - line2.c) / (line1.m - line2.m);
double y = this.m * x + this.b;
return new Point(x, y);
}
答案 1 :(得分:0)
当你有L1 = ax + c
和L2 = bx + d
时(a和b是斜率,c和d是截距)。
在线与L1 = L2
所以ax + c = bx + d
相交的点处
ax - bx = d - c
x = (d-c)/(a-b)
y = a * ((d-c)/(a-b) + c
。
如果我们想要找到y然后使用上面的x计算,我们有:
P((d-c)/(a-b), (ad-bc)/(a-b))
,
因此交点是:
let lstLength = {
'propA': 0,
'propB': 0,
};
sum = 0
for (prop in lstLength) {
sum += lstLength[prop]
}
if (sum === 0) {
alert('empty list')
} else {
alert('valid list')
}