检查一条线是否包含另一条线(由点定义)的Java算法

检查一条线是否包含另一条线(由点定义)的Java算法,java,algorithm,line,Java,Algorithm,Line,有人知道检查两条线是否相互包含的算法吗 我有交叉点检查的算法,但不起作用,例如: line A (1,1) to (2,2) line B (1,1) to (3,3) 代码: double s1_x=this.getRightPoint().getX()-this.getLeftPoint().getX(), s1_y=this.getRightPoint().getY()-this.getLeftPoint().getY(), s2_x=other.getRightPoint().getX

有人知道检查两条线是否相互包含的算法吗

我有交叉点检查的算法,但不起作用,例如:

line A (1,1) to (2,2)
line B (1,1) to (3,3)
代码:

double s1_x=this.getRightPoint().getX()-this.getLeftPoint().getX(),
s1_y=this.getRightPoint().getY()-this.getLeftPoint().getY(),
s2_x=other.getRightPoint().getX()-other.getLeftPoint().getX(),
s2_y=other.getRightPoint().getY()-other.getLeftPoint().getY(),
s=(-s1_y*(this.getLeftPoint().getX()-other.getLeftPoint().getX())+s1_x*(this.getLeftPoint().getY()-other.getLeftPoint().getY())/(-s2_x*s1_y+s1_x*s2y),
t=(s2_x*(this.getLeftPoint().getY()-other.getLeftPoint().getY())-s2_y*(this.getLeftPoint().getX()-other.getLeftPoint().getX())/(-s2_x*s1_y+s1_x*s2y);
if(Double.valueOf(s).isNaN()&&Double.valueOf(t).isNaN()){
返回true;
}

如果(s>=0&&s=0&&t则
s
t
的分母为零。 相反,试着用这个。 你知道“互相包含”的两条线具有相同的梯度。 你可以得到梯度1
m1=s1_y/s1_x
和梯度2
m2=s2_y/s2_x
此外,左线的右点必须位于右线的右点和左点之间。 因此,这将是:

(other.getRightPoint().getX() >= this.getRightPoint().getX()) && (other.getRightPoint().getX()<= other.getLeftPoint().getX())

(other.getRightPoint().getX()>=this.getRightPoint().getX())&&(other.getRightPoint().getX(),如果其中一条包含另一条直线,则坡度相等,并检查一条直线的一点和另一条直线的另一点的坡度r是否等于第一条坡度
(other.getRightPoint().getX() >= this.getRightPoint().getX()) && (other.getRightPoint().getX()<= other.getLeftPoint().getX())