Interpolation
I want a function that will give me the x,y,z coords, of a point of a line segment, in some given time.
e.g.
A---------B
Go from A to B, in 10 sec.
Assuming that (ABt) is 10 time units, and (ABs) is 20 space units, it would mean that i''d have a function like
f(t)=t*dif(ABs);
What if my line is in 3D space? How do i calculate each coord? based on (t)?
BTW: isn''t that called linear interpolation? Anywhere where i can find any helpfull examples on the subject, like splines interpolation, arc interpolation, etc... ?
thanks
... LEMMINGS ... LEMMINGS ... LEMMINGS ... LEM..... SpLaSh!...Could this be what we stand like before the mighty One?Are we LeMmIngS or WhAt!? ;)
The two basic lerp (linear interpolation) equations are:
result=source*(1-tween)+dest*tween
and the same result from
result=source+tween*(dest-source)
where tween=0 for result=source and tween=1 for result=dest
result=source*(1-tween)+dest*tween
and the same result from
result=source+tween*(dest-source)
where tween=0 for result=source and tween=1 for result=dest
hm, i think i should rephrase.
in 2D space (as i remembered later on), a line segment is expressed as:
y2-y1=((y2-y1)/(x2-x1))*(x2-x1)
what is the equation for the 3D space, and how do i interpolate it?
i''m also looking for the equations of SPLINES, ARC, etc... (in 3D space that is), and info on how to correctly interpolate ''em (hence linear interpolation doesn''t really work on curved segments).
in 2D space (as i remembered later on), a line segment is expressed as:
y2-y1=((y2-y1)/(x2-x1))*(x2-x1)
what is the equation for the 3D space, and how do i interpolate it?
i''m also looking for the equations of SPLINES, ARC, etc... (in 3D space that is), and info on how to correctly interpolate ''em (hence linear interpolation doesn''t really work on curved segments).
... LEMMINGS ... LEMMINGS ... LEMMINGS ... LEM..... SpLaSh!...Could this be what we stand like before the mighty One?Are we LeMmIngS or WhAt!? ;)
I think if line segments as deltas. So the line segment between the points A( 0, 1 ) and B( 5, 6 ) would be ( dx, dy ), where:
dx = 5 - 0 = 5
dy = 6 - 1 = 5
Interpolating the deltas is then trivial. Say you wanted to know the point 0.2 along the line. You''d just multiply the deltas by 0.2 and add that onto the first vertex of the line segment ( in this case A ). So:
dx *= 0.2 = 1;
dy *= 0.2 = 1;
position = ( 0 + 1, 1 + 1 )
= ( 1, 2 )
Simple eh?
Adapting this to use time equations is easy!
Say you wanted to go from A to B in 10 seconds, updating the position every second. You work out the deltas:
dx = dx/10 = 0.5;
dy = dy/10 = 0.5;
Then to update just add these deltas onto the last position. Of course, to calculate the point at a certain time, you would subsitute time_to_take_to_get_from_A_to_be/time_wanted. You can also update this to use equations of motion, so you could use velocity and time to calculate the current position.
Hope that helped a little.
dx = 5 - 0 = 5
dy = 6 - 1 = 5
Interpolating the deltas is then trivial. Say you wanted to know the point 0.2 along the line. You''d just multiply the deltas by 0.2 and add that onto the first vertex of the line segment ( in this case A ). So:
dx *= 0.2 = 1;
dy *= 0.2 = 1;
position = ( 0 + 1, 1 + 1 )
= ( 1, 2 )
Simple eh?
Adapting this to use time equations is easy!
Say you wanted to go from A to B in 10 seconds, updating the position every second. You work out the deltas:
dx = dx/10 = 0.5;
dy = dy/10 = 0.5;
Then to update just add these deltas onto the last position. Of course, to calculate the point at a certain time, you would subsitute time_to_take_to_get_from_A_to_be/time_wanted. You can also update this to use equations of motion, so you could use velocity and time to calculate the current position.
Hope that helped a little.
If at first you don't succeed, redefine success.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement