gkjohnson / coordinate-frame-converter Goto Github PK
View Code? Open in Web Editor NEWA Unity utility for simply converting between different coordinate frames.
License: Apache License 2.0
A Unity utility for simply converting between different coordinate frames.
License: Apache License 2.0
The ToQuaternion
function requires that the formed quaternion be stuff into Quaternion.Euler(Quaternnion.eulerAngles)
to avoid inconsistencies when using the AngleExtraction
class functions. For example
Quaternion q = Quaternion.Euler(90, -27, 170);
Matrix4x4 mat;
// Outputs (0, -90, 0), which is not equivalent!
mat = Matrix4x4.TRS(Vector3.zero, q, Vector3.one);
Debug.Log(AngleExtraction.ExtractEulerZXY(mat, out eulerResult) * Mathf.Rad2Deg);
// Outputs (163, -27, 170), which is!
mat = Matrix4x4.TRS(Vector3.zero, Quaternion.Euler(q.eulerAngles), Vector3.one);
Debug.Log(AngleExtraction.ExtractEulerZXY(mat, out eulerResult) * Mathf.Rad2Deg);
Why is this happening?
Verify that simply reversing the order of rotations properly applies a rotation in an intrinsic order.
https://en.wikipedia.org/wiki/Euler_angles#Intrinsic_rotations
https://en.wikibooks.org/wiki/Cg_Programming/Unity/Rotations
http://danceswithcode.net/engineeringnotes/rotations_in_3d/rotations_in_3d_part1.html
Unity uses floats for a lot of its operations, which means there can be quite a bit of accumulated error as rotations are converted. If the quaternions, vectors, and matrices were all doubles it would address the problem.
Right now the extractAngleXYZ
functions check against an epsilon when checking how to extract.
Right now you have to create negative or reversed rotation order frames to account for left handed or intrinsic rotation coordinate systems.
It might be less confusing to allow for setting constructor arguments that specify whether the frame is leftHanded
or intrinsic
/ movingBody
When extracting the euler angles using the angle extraction functions, the order doesn't seem quite right. We have to swap the row and col indices, for example, and there seem to be a few inconsistencies in the resultant values.
This needs some investigation.
http://danceswithcode.net/engineeringnotes/rotations_in_3d/rotations_in_3d_part1.html
ToQuaternion
basically only works with properly with Unity-frame axes because we have to assume certain conventions when pulling the new rotation order out of the axis.
There even seem to be subtle rotation offsets when consistently converting to a different frame like XYZ
instead of XY-Z
. Possibly because the euler application for quaternions assumes the axis conventions? This should be investigated (the problem can be seen when rotating like in the example image)
Either way, it might make things less confusing if it wasn't there
How to convert right hand matrix to left hand matrix(Unity) and back? Right hand matrix: right-handed coordinate system where positive X-axis points to the right, positive Y-axis away from the viewer and positive Z-axis points up. In the context of characters this means that positive X is right, positive Y is forward, and positive Z is up.
For use in any platform.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.