[RESOLVED] Calculating point position in space
Hi there. My name is Agustin Garzon. I'm not a Math Guru ;)
I'm a flash programmer trying to figure out how to solve a 2D problem for an animation I'm performing.
Basically, I know the position (x and y) of 5 points in a space. With that information, I must obtain the x and y position of a 6th point.
I've made a graph to clarify the problem:
http://www.AgustinGarzon.com/graph.gif
I would extremelly appreciate any help you can provide. If you do so, please try to put it in form of an equation easy to understand.
Thanks a lot!
Agustin Garzon.
Re: Calculating point position in space
Welcome to the Forums :wave:
First of all, don't show your email address unless you want spam galore. Put it in your profile if you want people to contact you.
As far as your question goes, you essentially need the intersection of two straight lines. The equation of a straight line is:
y = mx + c
where y and x are the coordinates of a point, m is the gradient of the line and c is the intercept on the y axis. This means that given the gradient and intercept, you can calculate any other point on the line.
With two points on the line, you can calculate the gradient and the intercept by filling in the values of x and y and solving simultaneously. You can thus find equations for the two intersecting lines by using the points on each of them. Then, by setting one equal to the other, you can find the intersection.
OK?
zaza
Re: Calculating point position in space
Good luck solving simultaneous equations via code is hard, zaza, if you know an easy way to do it it would be great to know.
Re: Calculating point position in space
Dear Zaza,
Thanks for such a prompt response ;)
I've problems understanding your posting. How can you calculate the values for m and C using any of the known values? (the X and Y coordinates of the given points)
Anyway, I'll post back the full solution as soon as I've solved it. I've asked at a Math Forum but they are very advanced for my level of comprehension in this matter.
Cordially,
Agustin Garzon.
PS: A fabulous forum VBForums... isn't it?
Re: Calculating point position in space
Ok, you need the intersection of the line between points A and B, and the line between D and E.
Let's say A is at the coordinates (Ax, Ay), B is at (Bx, By) etc.
Use y=mx+c:
Ay = m*Ax + c
By = m*Bx + c
because these two are on the same line. Hence:
c = Ay - m*Ax = By - m*Bx
Rearranging for m:
m*Ax - m*Bx = Ay - By = m * (Ax - Bx)
Hence m = (Ay - By) / (Ax - Bx)
This is the definition of the gradient m, it is the change in y divided by the change in x.
Now that you know m, you can put it back into one of the other equations to get c:
c = Ay - m*Ax
and you have the equation of the line. The general solution is:
Ay = m*Ax + c
where m and c are the gradient and y-intercept respectively, so you can put in any value of Ax and get the value of Ay that lies on the line. Etc.
Do this also using the points D and E to get the equation of the second line.
So now you have two lines:
y = mx+c is the line through A and B
y = Mx+C is the line through D and E
You want to find the point (X,Y) which lies on both lines.
Y = mX+c
Y = MX+C
gives you mX+c = MX+C and you can rearrange for X:
c-C = X(M-m)
X = (c-C) / (M-m)
and now that you know X, you can fill it back into the equations above to get Y.
In summary, for coding purposes of line intersection:
m = (Ay - By) / (Ax - Bx)
c = Ay - {Ax * [(Ay - By) / (Ax - Bx)]}
M = (Dy - Ey) / (Dx - Ex)
C = Dy - {Dx * [(Dy - Ey) / (Dx - Ex)]}
X = (c-C) / (M - m)
Y = M * [(c-C) / (M-m)] + C
zaza