Take the 2-minute tour ×
Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. It's 100% free, no registration required.

I have two points in 3D space:

point $A = (1,2,3)$

point $B = (4,7,6)$

I want to find a third point between the two, where $z = 5$

So, point $C = (x,y,5)$

How can I calculate $x$ and $y$ for point $C$?

Thanks.

share|improve this question
    
When you formalize 'between', you'll be able to answer that for yourself. –  Alexei Averchenko Jul 28 '11 at 13:31
add comment

1 Answer 1

up vote 5 down vote accepted

The points on the line segment between $(a,b,c)$ and $(p,q,r)$ have coordinates $$(sa+(1-s)p,\: sb+(1-s)q, \: sc+(1-s)r)\quad\quad\text{(Equation $1$)},$$ where $0 \le s \le 1$.

In our case we have $c=3$ and $r=6$. So $$3s+6(1-s)=5.$$ Solve for $s$. We obtain $s=1/3$. Now the other coordinates are easy to find from Equation $1$.

We get $$x=(1/3)(1)+(2/3)(4)=9/3=3,$$ $$y=(1/3)(2)+(2/3)(7)=16/3.$$

Equation $1$ says that the coordinates of any point between two given points is a "weighted average" of the given coordinates. In our particular case, the number $5$ is twice as far from $3$ as it is from $6$. So the point we are looking for is $2/3$ of the way from $(1,2,3)$ to $(4,7,6)$. Apply the $1/3$, $2/3$ weighting to the other two coordinates.

share|improve this answer
    
Thanks a lot, this works well in my new algorithm. –  Mustafa Jul 28 '11 at 15:07
    
@Mustafa: Great! Sometimes the simple mathematical solution is not the best real-world programming solution. It is good that you had no trouble developing the general formula starting from the particular example. –  André Nicolas Aug 19 '11 at 14:19
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.