Line2D.Double telling me lines are intersecting when they don't
-
09-12-2019 - |
Question
In making a project for class, we are defining shapes (triangle, quadrilateral, pentagon) without the help of the Shape
class obviously.
In my checks to make sure the shape is valid, I use Line2D.Double linesIntersect()
to determine if the connections between two sets of points (p1-p4 x p2-p3)
. When I have my input to linesIntersect(double,double,double,double,etc)
set to:
p1(-1,-1)
p2(-1,-11)
p3(5,0)
p4(5,5)
It tells me that the line from p1
to p4
crosses the line from p2
to p3
. When in fact they should be two diagonal parallel lines.
Any help?
Solution
Sorry, but based on what you typed, p1, p4 is not parallel to p2, p3.
p1(-1,-1)
p4(5,5)
p2(-1,-11)
p3(5,0)
p1, p4 has a slope of 1.
p2, p3 has a slope of 11/6 or 1.83
If you want the lines to be parallel, then you need to change p3.
p3(5,-5)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow