# 3d points to rotation matrix of orientation

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.

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.

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?

• Can you clarify what format your rotations are in, and what coordinate system you're using? Commented May 15, 2020 at 14:37
• This sounds like the lookAt functionality, have you tried searching for that term and how it works? Would that solve your problem? Commented May 15, 2020 at 14:48
• Yes a lookat funtion to a point
– runs
Commented May 15, 2020 at 14:53
• "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) Commented May 15, 2020 at 15:12

d = normalize(d);