Jump to content
  • Advertisement
Sign in to follow this  
LonelyStar

Intersection of lines - optimization if perpendicular?

This topic is 4108 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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


Link to post
Share on other sites
Advertisement
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
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
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
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

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
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
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
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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!