Intersection of lines - optimization if perpendicular?

Recommended Posts

Hello dear community, I can figure out the point of intersection of 2 lines. Now I have 2 lines which I know are perpendicular to each other! Is there a opzimization for finding the point of intersection in this special case? Thanks! Nathan

Share on other sites
Are the lines guaranteed to be perpendicular before entering the function that calculates the intersection? Only in that case the optimization is worthwhile since otherwise the perpendicular case is just an arbitrary case to optimize for.

Share on other sites
I can think of one 'optimisation'. Probably not worth it, unless it's really special (axis aligned lines).

Share on other sites
Quote:
 Original post by arithmaAre the lines guaranteed to be perpendicular before entering the function that calculates the intersection? Only in that case the optimization is worthwhile since otherwise the perpendicular case is just an arbitrary case to optimize for.

Yes, they always are perpendicular.

Share on other sites
If the two lines are perpendicular and you have two initial points on them then the problem boils to projecting a point on another line.

Share on other sites
Vector IntersectPerpendicularLines(const Vector& A0, const Vector& A1, const Vector& B0, const Vector& B1){    Vector A = A1 - A0;    Vector D = B0 - A0;    float ad = A.DotProduct(D);    float a2 = A.DotProduct(A);    return A0 + A * (ad / a2);}

[Edited by - oliii on March 22, 2007 6:23:01 PM]

Share on other sites
Quote:
 Original post by oliii *** Source Snippet Removed ***

That's a great example of why documentation and testing are such a good idea... [smile]

Share on other sites
Quote:
 Original post by arithmaIf the two lines are perpendicular and you have two initial points on them then the problem boils to projecting a point on another line.

That makes sense! Thanks for the help!
And thanks for the code-example, Oliii!

Share on other sites
Quote:
Original post by jjd
Quote:
 Original post by oliii *** Source Snippet Removed ***

That's a great example of why documentation and testing are such a good idea... [smile]

Heh, I usually do. but that should work (I think) [grin]

Share on other sites
It shouldn't even compile. ^_^

Share on other sites
Oooh the unbearable shame! [grin]

Fixed.

Create an account

Register a new account

• Forum Statistics

• Total Topics
628334
• Total Posts
2982145

• 9
• 24
• 9
• 9
• 13