Finding a y on a line with x?
Alright this is probally basic for some, but i need to find the y value of a point with x on a sloping 2d line.
So ive got the start and end points, and a x within that line.
I looked at an old maths book with linear equations, though they were all based on knowing the y intercept, and line in question is draw from two mouse clicks, so couldn''t figure out how to apply it.
Thanks of any help!
What you want to do is called "Linear Interpolation."
Say one point is (X1,Y1) and the second is (X2,Y2) and the point you have in between these two points is (X,Y). So:
(Y-Y1)/(X-X1)=(Y2-Y1)/(X2-X1)
just simplify that. It is basicall saying that for all 3 points to be co-linear, the slopes between any two of the line segments must be equal.
Hope that makes sense!
Say one point is (X1,Y1) and the second is (X2,Y2) and the point you have in between these two points is (X,Y). So:
(Y-Y1)/(X-X1)=(Y2-Y1)/(X2-X1)
just simplify that. It is basicall saying that for all 3 points to be co-linear, the slopes between any two of the line segments must be equal.
Hope that makes sense!
Turring Machines are better than C++ any day ^_~
I found a solution after reading about Bresenham''s line drawing, which fits my problem nicely.
// the bit that i needed.
float m = (y1 - y0) / (x1 - x0);
float yi = y0 + m * (xi - x0);
// the bit that i needed.
float m = (y1 - y0) / (x1 - x0);
float yi = y0 + m * (xi - x0);
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement