0
$\begingroup$

I'm doing some 3D graphics work and hit a snag. The problem should be easy enough, but I couldn't find any general solution after some personal brainstorming. I kinda feel stupid for asking something that's probably a trivial trigonometry problem, but here goes:

I have two 3-dimensional points: $ P _ 1 $ and $ P _ 2 $. Starting from $ P _ 1 $, I need to move towards $ P _ 2 $ by "$ N $" units. $ N $ is guaranteed to be less than the distance from $ P _ 1 $ to $ P _ 2 $. Thus, I need to find the point $ P _ 3 $ which is $ N $ units away from $ P _ 1 $, moving from $ P _ 1 $ towards $ P _ 2 $. It's using $ x $, $ y $, and $ z $ values, but a solution with just $ x $ and $ y $ is probably sufficient for me to figure the rest out.

  • 0
    You need the unit vector for $P_1P_2$ multiplied by $N$ and added to $P_1$2017-02-24
  • 1
    So, in other words, (( P2 - P1)/|P2-P1|) * N) + P12017-02-24
  • 0
    Yes that's it..2017-02-24
  • 0
    Note that that formula works even without any restrictions on $N$. If $N$ is greater than the distance between $P_1$ and $P_2$, then $P_2$ is between $P_1$ and $P_3$. If $N$ is negative, then $P_1$ is between $P_2$ and $P_3$.2017-02-24

0 Answers 0