Jump to content
  • Advertisement
Sign in to follow this  
InsaneBoarder234

Line Intersection

This topic is 4063 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

In the source code with the book Tricks of the Windows Game Programming Gurus there is a function to clip lines to a predefined clipping rectangle. The function uses the following formula to get the Y co-ordinate where the line crosses the left hand side of the clipping rectangle... yIntercept = y1 + (clipX - x1) * (y2 - y1) / (x2 - x1); Where (x1, y1) and (x2, y2) are the end points of the line being clipped, and clipX is the X co-ordinate of the left hand side of the clipping rectangle (the line x=clipX). I recognise the last part of this formula as being one representation of the equation of a line: gradient m * (y2 - y1) / (x2 - x1). As such I assume the other part of the formula has something to do with the gradient of the line, however my maths is quite rusty and I don't understand exactly what it is doing and how. Can anyone explain this to me? Also while I'm on the subject, can anyone provide me with links to any articles or books that might help me to brush up my maths skills a bit? - I'm about to go searching through the articles section of this site to see what I can find there for now but if anyone can recommend anything from experience that would be awesome, thanks.

Share this post


Link to post
Share on other sites
Advertisement
you are a bit confused its (what you typed isn't even an equation...):
the equation for the gradient m is
m = (y2-y1)/(x2-x1)

that is, the ratio between change on Y to the change on X.
when you change some X the Y changes based on this ratio
(this ratio is the same all over the line)

so in other words:
Y = initial_y + m* delta_x
(delta_x = x2 - initial_x)

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!