• Advertisement
Sign in to follow this  

Moving dot between two points in 3D space

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

Hi guys/gals, I'm having a problem coming up with a way to visualize a moving dot along some invisible line between two objects in 3D space. So after the start and end objects are drawn at their respective X, Y and Z locations, I want to draw a dot moving from one object to the other in a straight line. I'm thinking that on each subsequent redraw of the scene, I have to move that dot along some invisible line to make it look like the dot is moving from one object to the other. However, I'm not sure on how to go about accomplishing this, so I was hoping on getting your input. Thanks for your help.

Share this post

Link to post
Share on other sites
There are a variety of forms one could use to model a straight line, but for these purposes, the parametric form should serve your needs well. The basic idea is that you have six known quantities, x1, y1, z1, and x2, y2, z2. These are your two points, between which you want the other point to move. What you want to determine is x3, y3, z3, the location of a moving point at some particular time. You can calculate these three values independently of each other, which makes this very convenient and easy. To calculate x3, you only need to worry about x1 and x2. The ys and zs are irrelevant. The most basic equation would be:

x3 = c1x·t + c2x

but you don't know what c1x and c2x are; they are constants of some (as of yet) unknown value. Fortunately, there is an easy way to calculate these constants, using what you already know:

c1x = x2 - x1
c2x = x1

Your overall equation for x3 could then be written out as:

x3 = (x2 - x1)·t + x1

To calculate y3 and z3, just substitute in ys or zs for xs. The equations are exactly the same; you just calculate a different dimension of the point.

y3 = (y2 - y1)·t + y1
z3 = (z2 - z1)·t + z1

So now you have your three equations, one for x, one for y, and one for z. And you have that variable t, representing time, or one particular point on the line. If you plug in the value 0 for t, then your result will be the same as point 1. If you plug in the value 1 for t, then your result will be the same as point 2. Anything in between 0 and 1 will be between point 1 and 2, and how close t is to 0 or 1 will be exactly proportional to how close the resulting point is to point 1 or point 2. t = 1/2 for example will be exactly half way between the points. So now all you need to do is vary t so that it starts at 0, moves up by increments at whatever rate you consider appropriate, until it reaches 1. This will result in the calculated point being moved from point 1 to point 2.

Share this post

Link to post
Share on other sites
here's one way to do it.

its easy to visualize this in 2d (x,y). Once you're comfortable with that, its an easy step up to 3d (x,y,z).

so, as an example, lets say you're moving from point a to point b in 2d space:

a = (4,4)
b = (6,6)

first, determine the vector v from point a to point b, by subracting a from b.

v = b - a = (2,2)

next, lets say you want to move between a and b in 4 seconds. Along comes t to help, which is a fraction representing elapsed time by overall time.

t = elapsed / total = x / 4

now, we can plot the position like this:

pos = a +(v *t)


a +(v *0.0) = (4,4)
a +(v *0.5) = (5,5)
a +(v *1.0) = (6,6)

hope that helps! (edited due to mathlexia)

Share this post

Link to post
Share on other sites

Your explanation made perfect sense the first time I read it, thanks for making it so easy to understand (I basically got it to work using the three formulas you provided and it works like a charm)


your alternative method was also very clear, thanks for your input as well.

Again, thanks to both of you for your time and effort.


Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement