-
Notifications
You must be signed in to change notification settings - Fork 4.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Quaternion: Extract yaw, pitch, and roll #38567
Comments
I couldn't figure out the best area label to add to this issue. If you have write-permissions please help me learn by adding exactly one area label. |
Beep boop. Tagging subscribers to this area: @tannergooding (according to the label assigned to #38566) |
Tagging subscribers to this area: @tannergooding |
I prefer PitchYawRoll. Or add all their friends? (RollPitchYaw, PitchYawRoll, PitchYawPitch, YawRollYaw, ...) |
There's no point in having that whole family. Although I would prefer +X right, +Y up, +Z forward, the order I chose keeps the convention of quaternion.ExtractYawPitchRoll(out float yaw, out float pitch, out float roll);
new Vector3(pitch, yaw, roll); |
@Ramobo Sorry for the late reply.
I see your point. It's great to have a counterpart of
Due to a disagreement on terminology, it may be simply wrong. In general, (*Mathematica*)
EulerMatrix[{p, q, r}, {2, 1, 3}] != EulerMatrix[{q, p, r}, {1, 2, 3}]
EulerMatrix[{p, q, r}, {2, 1, 3}] != RollPitchYawMatrix[{p, q, r}, {2, 1, 3}]
BTW, I think |
Sorry, I don't understand. I'm not a matrix and quaternion black wizard or whatever, I just want to be done with core graphics already.
Also sadly, everything is right-handed with no left-handed methods. I'm up for a proposal to add left-handed methods. I literally had to copy some methods from SharpDX to get a left-handed view and projection matrix, and the pitch was still counter-clockwise while the other two were clockwise. .NET math is neglected in general. |
Your Proposed API is good. But some part of Usage Examples could be misleading. They are mathematical black magic. You said that. My key point is that the yaw in X, Y, and Z are definitely unambiguous because they are the field/component names of Of course, I can say it's Microsoft's fault. I just wondering why we did not provide a pair of methods ( My apologies. I just realize that what I really want to do is to protest the already-done approval of the poor-documented API |
I agree that it is with what you're talking about, but it must absolutely be considered in general.
By ambiguous, I mean: If you say "X axis", what does that mean? Is that yaw, pitch, or roll? Yes, there are coordinate systems where X is yaw. I agree with the rest. |
"X axis" means the axis generated/specified by Vector3.UnitX. This definition does not depend on the graphics system. Matrix4x4 m1 = Matrix4x4.CreateFromQuaternion(Quaternion.CreateFromYawPitchRoll(argle1, argle2, argle3);
Matrix4x4 m2 =
Matrix4x4.CreateFromAxisAngle(Vector3.UnitZ, /*dotnet's roll*/argle3) *
Matrix4x4.CreateFromAxisAngle(Vector3.UnitX, /*dotnet's pitch*/argle2) *
Matrix4x4.CreateFromAxisAngle(Vector3.UnitY, /*dotnet's yaw*/argle1); Noted that /*OpenTK*/Matrix4 m3 = Matrix4.CreateFromQuaternion(/*OpenTK*/Quaternion.FromEulerAngles(argle1, argle2, argle3));
Matrix4x4 m4 =
Matrix4x4.CreateFromAxisAngle(Vector3.UnitX, /*OpenTK's roll*/argle3) *
Matrix4x4.CreateFromAxisAngle(Vector3.UnitZ, /*OpenTK's pitch*/argle1) *
Matrix4x4.CreateFromAxisAngle(Vector3.UnitY, /*OpenTK's yaw*/argle2);
// (What an odd re-ordering!) The matrices m3 and m4 should match. For some one looking for an implementation public static void CreateFromYawPitchRoll(Quaternion r, out float yaw, out float pitch, out float roll) {
yaw = MathF.Atan2(2.0f * (r.Y * r.W + r.X * r.Z), 1.0f - 2.0f * (r.X * r.X + r.Y * r.Y));
pitch = MathF.Asin(2.0f * (r.X * r.W - r.Y * r.Z));
roll = MathF.Atan2(2.0f * (r.X * r.Y + r.Z * r.W), 1.0f - 2.0f * (r.X * r.X + r.Z * r.Z));
} |
Background and Motivation
Essential for turning rotation outputs into non-black-wizard-mathematician-friendly counterparts.
Proposed API
namespace System.Numerics { public class Quaternion : IEquatable<Quaternion> { + public void ExtractYawPitchRoll(out float yaw, out float pitch, out float roll); } }
Since the inputs for
Quaternion.CreateFromYawPitchRoll(...)
are in radians, the outputs for the proposed method should also be in radians.Usage Examples
Uses a constant from #38566.
Alternative Designs
Vector3
instead. I heard that you can't since you have to be coordinate system-agnostic.Risks
None.
The text was updated successfully, but these errors were encountered: