0

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?

Boris Pavlović
  • 63,078
  • 28
  • 122
  • 148

1 Answers1

1

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)
Gilbert Le Blanc
  • 50,182
  • 6
  • 67
  • 111
  • true, my bad, but the fact still remains that the two lines start and end at the points and at no point do they intersect. We did end up finding out what was wrong in our use of linesIntersect(), thank you for the response! – user1231771 Mar 07 '12 at 23:59
  • @user1231771: I think the intersect method assumes the lines extend past their end points. – Gilbert Le Blanc Mar 08 '12 at 13:16