Let’s say I have an entity in 3d space and I know its position vector (x, y, z) and its velocity vector (so its orientation in space).
Starting from known point A I want to reach known point B in two steps:
a) turn, following a circular path with a known radius R, until point C
b) go straight from point C to final point B.
Speed (scalar value) is not important. Velocity (vector) is known, so I guess it should define the plane on which the circle resides, being tangent to it, together with the line between A and B…
I want to know how to find coordinates (x, y, z) for C and the velocity vector of the entity being there.
Update: see the working demo!
If I understand correctly, your situation (in the plane containing A, B and v) is as shown in the diagram below. The points A and B are given, as is the vector v and the distance r. You want to find the point C.
Well, let the vector w = (−v̂y, v̂x) be a unit vector perpendicular to v. Then O = A + r w.
Now, |C − O| = r and (C − B)·(C − O) = 0 (where · is the dot product). Combine these to get a quadratic equation, which you can solve to find the two possible positions for C. Then pick the one with the right sign for (C − B)×(C − O).
(There’s a second choice for the centre of the circle, O = A − r w, representing turning clockwise instead of anticlockwise. This gives you another possibility for C. I guess you’ll have to use some heuristic to decide which one you prefer: maybe the one with smallest ∠AOC.)
St0rM asks for help with doing this in 3D (see comments). That’s easy! The plane containing A, B, and v has normal vector n = (A − B) × v. Let u = n × v be a vector perpendicular to both n and v, and let w = û (the unit vector in the direction of u).
You’ll also need to take into account the constraint that C lies in the same plane as A: C·n = A.n, and “the right sign for (C − B)×(C − O)” becomes “the right sign for (C − B)×(C − O)·n“.
Having trouble solving this system of equations?
Well, if (C − B)·(C − O) = 0, then (C − O + O − B)·(C − O) = 0, therefore (C − O)·(C − O) + (O − B)·(C − O) = 0, therefore C·(O − B) = O·(O − B) − r2.
You’ll note that this is the equation for a plane, and so is C·n = A.n. Intersect these two planes (see Wikipedia for details — you can use the simpler solution since the planes are orthogonal and can easily be made orthonormal) to get the equation of a line on which C lies: C = H + λL, say, where L = n×(B − O). Then use (C − O)·(C − O) = r2 to turn this into a quadratic equation in λ. You’ll find that the quadratic equation simplifies quite a bit if you rewrite the equation of the line as C = H + λL + O so that occurrences of “− O” disappear.
Here’s an implementation in Python using
numpyto do the vector algebra. I’m sure you can figure out how to convert this to the language of your choice.