# 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.

## 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 on other sites
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)

1. 1
2. 2
Rutin
24
3. 3
4. 4
JoeJ
19
5. 5

• 14
• 26
• 11
• 11
• 9
• ### Forum Statistics

• Total Topics
631771
• Total Posts
3002253
×