I have two points (A, B) and the length of d. How can I find point C?
2 Answers
\$\begingroup\$
\$\endgroup\$
5
Compute a vector V
from A
to B
, and normalize it.
V = (B - A) / |B - A|
Since the vector is normalized, it will have a length of one, and it will indicate the direction of B
relative to A
. If you then scale the vector by d
you will have the displacement from A
to C
V' = d * V
which you can simply add to A
to yield C
:
C = V' + A
-
\$\begingroup\$ btw: could anyone recommend me a book where I can learn about stuff like that? :) \$\endgroup\$– eempeeOct 10, 2011 at 20:40
-
\$\begingroup\$ 3D Math primer is a good one: amazon.com/Primer-Graphics-Development-Wordware-Library/dp/…. \$\endgroup\$– Ricky AHOct 11, 2011 at 8:03
-
\$\begingroup\$ Didn't read this one, but I've been told that is also pretty good amazon.com/Mathematics-Programming-Computer-Graphics-Second/dp/… \$\endgroup\$– Ricky AHOct 11, 2011 at 8:05
-
1\$\begingroup\$ See this question: gamedev.stackexchange.com/questions/1210/… \$\endgroup\$– user1430Oct 11, 2011 at 15:06
-
\$\begingroup\$ btw this is the last couple steps in ray intersection algorithms: you figure out how far along the ray the intersection point is, and then you get the coordinates of the point geomalgorithms.com/a05-_intersect-1.html#Plane-Intersections \$\endgroup\$– jhockingDec 17, 2013 at 17:42
\$\begingroup\$
\$\endgroup\$
In case your d is a ratio instead of a length, e.g 0.5 puts it on equal distance from A and B, you can do the following and avoid a normalization:
C = A * (1 - ratio) + B * ratio