Sign in to follow this  
LonelyStar

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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
Share on other sites
LonelyStar    192
Quote:
Original post by arithma
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.


Yes, they always are perpendicular.

Share this post


Link to post
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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
Share on other sites
LonelyStar    192
Quote:
Original post by arithma
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.


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

Share this post


Link to post
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 this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this