tags:

views:

250

answers:

3

I have a line that exists in 3d that is between two known points: {X1, Y1, Z1} and {X2, Y2, Z2}.

I also know that I am a certain distance for one of the points: D

How can I determine what the coordinates of the point where I am after moving D from {X1, Y1, Z1}?

Thanks

+1  A: 

First, determine the length of the line segment:

d=sqrt((X1-X2)^2+(Y1-Y2)^2+(Z1-Z2)^2))

You are moving D from P1=(X1,Y1,Z1) toward P2=(X2,Y2,Z2). This puts you at the point (X3,Y3,Z3):

{XYZ}3={XYZ}1+(D/d)*({XYZ}2-{XYZ}1})

Where you expand that into 3 equations, one for each of X, Y, and Z.

This works because you are D/d of the way between P1 and P2. Check: Say D=d. Then you should be at exactly P2.

wrang-wrang
A: 

Take the vector between the two points

<X2-X1, Y2-Y1, Z2-Z1>

Turn that into a unit vector pointing in the same direction but with length 1. You do that by dividing by the distance between the two points:

         <X2-X1, Y2-Y1, Z2-Z1>
---------------------------------------
sqrt((X2-X1)^2 + (Y2-Y1)^2 + (Z2-Z1)^2)

Then multiply that by D and add to your original point to get the new point.

                            <X2-X1, Y2-Y1, Z2-Z1>
(X1, Y1, Z1) + D * ---------------------------------------
                   sqrt((X2-X1)^2 + (Y2-Y1)^2 + (Z2-Z1)^2)
John Kugelman
+2  A: 

Assuming you want to move the distance D from point 1 to point 2 :

P1 = [ X1, Y1, Z1 ]
P2 = [ X2, Y2, Z2 ]

The line vector can be described as :

V = P2 - P1 = [ Xv = X2 - X1, Yv = Y2 - Y1, Zv = Z2 - Z1 ]

The line's length can be determined as :

VL = SQRT(Xv^2 + Yv^2 + Zv^2)     // ^2 = squared

The line's versor aka the unit vector can be determined as :

v = V / VL = [Xv / VL, Yv / VL, Zv / VL]

The target point PD can be determined as :

Pd = P1 + D * v // Starting from P1 advance D times v

Please note that P1 and v are vectors and D is a scalar

Maciek