0
\$\begingroup\$

I have a vector in a 3D view, defined by a point p1(x1, y1, z1) and a rotation r1(x1, y1, z1). I can get a direction and a yaw. I need that vector to point another point p2 (x2, y2, z2). So I need a new rotation.

3d

Coordinates: Coordinates are expressed like this: (5, 45, -12) This refers to the position where X=5, Y=45 and Z=-12. The 3 letters are called “axes”: Y is for the height. X and Z are for the horizontal position. Rotation: Yaw and pitch (radians). It can be converted to degrees.

yaw_pitch

I get this function, where d is the direction (vector between pos1 and pos2):

d = normalize(d); double yaw = Math.Atan2(d.X, d.Y); double pitch = Math.Asin(d.Z)

Is it Ok?

\$\endgroup\$
4
  • \$\begingroup\$ Can you clarify what format your rotations are in, and what coordinate system you're using? \$\endgroup\$
    – DMGregory
    Commented May 15, 2020 at 14:37
  • \$\begingroup\$ This sounds like the lookAt functionality, have you tried searching for that term and how it works? Would that solve your problem? \$\endgroup\$ Commented May 15, 2020 at 14:48
  • \$\begingroup\$ Yes a lookat funtion to a point \$\endgroup\$
    – runs
    Commented May 15, 2020 at 14:53
  • \$\begingroup\$ "Is it OK?" - You tell us! Does it work as desired when you try it? If not, in what way does it deviate from what you want? (It looks like it might be made for a Z = up = positive pitch coordinate system though, so you'll have a little bit of swapping to do for your case) \$\endgroup\$
    – DMGregory
    Commented May 15, 2020 at 15:12

1 Answer 1

-1
\$\begingroup\$

It seems to work using the following formulas:

d = normalize(d); 
double yaw = Math.Atan2(-d.X, d.Z); // Counter-clockwise from Z+
double pitch = -Math.Asin(d.Y);     // Y = up, positive pitch = down
\$\endgroup\$
0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .