Compute a location given the current location, an angle and a distance

Hi!

I’m using Unreal 5.3 with C++ and I have a question about mathematics.

Given a location (x, y ,z) I want to compute a point given an angle an a distance from the current point. How can I compute it?

I want to keep the X component, and compute the Y and Z values.

Thanks!

Distance is just vector * distance.

So say you take forward vector, you times it by 1000, you now have a point in space that’s 1000 units forward.

Rotating vectors manually is basically matrix math rather than trig.
You cannot really simplify it.
You are simply better off learning your SoCaThoA
principles and doing some trig to apply it to the matrix math - or lesrning trig and using trig functions.

Vector Cross Vector gives you an axis that’s between the 2 vectors.

In c++ you have FVector you can poke around in, pull a rotator from and rotate by using the built in kismeth functions.

You probably want something like rotateAngleAxis or similar.
Where you feed in a degree or radian value and get the rotated result returned.

Either way having an “angle” means nothing. You need to know what axis that is relative to, and its 2d math, which only applies to a single axis…

Adding normalized vecors could actually end up being what you need if you have something like a start and and end vector (6 points)
And you need to determine the vector needed to multiply and reach the end point…
Not sure that 100% holds true though.

1 Like

In general, angles end up being the wrong domain to work in about 98% of the time in 3D simulation and geometry. You’re almost always better off thinking in terms of coordinate systems and transforms and basis vectors. The one case where angles are still needed, is when the UI itself is in terms of angles – if the captain says “come to 30 degrees larboard” you have no other option than to plug the 30 degrees into some function that turns it into the appropriate matrix (or quaternion, or rotator.)

So, in unreal engine, because you want the X axis to be the axis you rotate around, the code is pretty simple:

  1. Create a rotator for “rotate X amount around X axis”
  2. Use rotator to rotate the Forward vector of whatever your “current point” is (a point doesn’t have a direction, so some kind of current actor is likely involved.)
  3. Multiply the rotated-forward by the distance
  4. Add that result vector to the position of the “current point”
2 Likes