Line2d.intersectsLine(Line2D line) ?

R

Rod Nibbe

The Line2D class has a boolean method, intersectsLine(Line2D line), that
tests if two Line2D objects intersect. Why do you suppose it's boolean
instead of, say, returning a Point2D object with the actual point of
intersection, or null if they don't intersect? The method has to compute
the intersection anyway, so why not return the result?

I realize it's relatively simple to do this in a separate method, of
course, but it just seemed so obvious that the caller might actually
want the point of intersection -- like me!

-RKN
 
J

Jacob

Rod said:
The Line2D class has a boolean method, intersectsLine(Line2D line), that
tests if two Line2D objects intersect. Why do you suppose it's boolean
instead of, say, returning a Point2D object with the actual point of
intersection, or null if they don't intersect? The method has to compute
the intersection anyway, so why not return the result?

I realize it's relatively simple to do this in a separate method, of
course, but it just seemed so obvious that the caller might actually
want the point of intersection -- like me!

I think Line2D does this check *without* computing the
exact point of intersection, maybe due to performance
as this might be critical code?

Also, the computation is not as straight forward as you
might think; Look at the method findLineSegmentIntersection()
in http://geosoft.no/software/geometry/Geometry.java.html
where this problem has been solved.
 
R

Rod Nibbe

Yeah, it occurred to me after submitting my post that what you said
could be true, that the implementation doesn't need to compute the point
of intersection.

Thanks also for the link to the code. I have an old Fortran
implementation around here somewhere, and my recall is that the algebra
wasn't too complicated.

-RKN
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,432
Messages
2,571,681
Members
48,796
Latest member
Greg L.

Latest Threads

Top