Intersection of lines - optimization if perpendicular?

Recommended Posts

LonelyStar    192
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
arithma    226
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
oliii    2196
I can think of one 'optimisation'. Probably not worth it, unless it's really special (axis aligned lines).

Share on other sites
LonelyStar    192
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
arithma    226
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
oliii    2196
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
jjd    2140
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
LonelyStar    192
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
oliii    2196
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
Raghar    96
It shouldn't even compile. ^_^

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

Fixed.