Comments and answers for "Generate a 3x3 rotation matrix from a Matrix4x4"
http://answers.unity.com/questions/875348/generate-a-3x3-rotation-matrix-from-a-matrix4x4.html
The latest comments and answers for the question "Generate a 3x3 rotation matrix from a Matrix4x4"Answer by Bulvyf
http://answers.unity.com/answers/1164873/view.html
Recommend you investigate the use of Math.NET numerics libraries in (C# solutions). For me to get the numerics library to work with the Unity3D C3(v3) scripts, I had to
1. download Math.NET Numerics via NUGET to a full .NET 4+ project (alternatively you could download from GITHUB at [https://github.com/mathnet/mathnet-numerics][1] ).
2. Then move the MathNet.Numerics.dll to the Assets/Plugins directory
3. Close and (re) open Unity, for Unity to load the dll
as a reference within its older Visual Studio project version.
You can delete or unload the the previously mentioned .NET 4.5 project, thereafter.
From there, it's possible to use their matrix and vector libraries (with so much more as well).
Cross reference on how to include a dll in Unity:
[http://answers.unity3d.com/questions/333829/including-a-dll-in-unity.html][2]
Explanation for using a Math.NET Matrix:
[http://numerics.mathdotnet.com/Matrix.html][3]
Some links on using Matrices with their Linear Regression examples.
- http://numerics.mathdotnet.com/Regression.html
- http://christoph.ruegg.name/blog/linear-regression-mathnet-numerics.html
- http://www.imagingshop.com/linear-and-nonlinear-least-squares-with-math-net/
I hope that's of use?
[1]: https://github.com/mathnet/mathnet-numerics
[2]: http://answers.unity3d.com/questions/333829/including-a-dll-in-unity.html
[3]: http://numerics.mathdotnet.com/Matrix.htmlSun, 03 Apr 2016 22:11:23 GMTBulvyfAnswer by zerophase
http://answers.unity.com/answers/876151/view.html
In case anyone else needs a 3x3 Matrix here's how I did it:
private static float[][] identityMatrix =
{
new [] {1.0f, 0.0f, 0.0f},
new []{0.0f, 1.0f, 0.0f},
new []{0.0f, 0.0f, 1.0f}
};
public static float[][] QuaternionTo3x3(this Quaternion value)
{
float[][] matrix3x3 =
{
new float[3],
new float[3],
new float[3],
};
float[][] symetricalMatrix =
{
new float[3] {(-(value.y * value.y) - (value.z * value.z)), value.x * value.y, value.x * value.z},
new float[3] {value.x * value.y, (-(value.x * value.x) - (value.z * value.z)), value.y * value.z},
new float[3] {value.x * value.z, value.y * value.z, (-(value.x * value.x) - (value.y * value.y))}
};
float[][] antiSymetricalMatrix =
{
new[] {0.0f, -value.z, value.y},
new []{value.z, 0.0f, -value.x},
new []{-value.y, value.x, 0.0f}
};
for (int i = 0; i < 3; i++)
{
for (int j = 0; j < 3; j++)
{
matrix3x3[i][j] = identityMatrix[i][j] +
(2.0f*symetricalMatrix[i][j]) +
(2.0f*value.w * antiSymetricalMatrix[i][j]);
}
}
return matrix3x3;
}Wed, 14 Jan 2015 04:22:43 GMTzerophaseComment by Jeff-Kesselman
http://answers.unity.com/comments/876086/view.html
Any direct mapping is going to be dependent on unpublished and thus unstable assumptions about the internal layout of Unity's matrices.
I suggest you extract a quaternion from the 4x4 and then convert back to your 3x3 representation. That will at least be stable.
Its more work but if you intelligently cache then you shouldn't have to do it that often.
If you REALLY want to write unstable code, then you should be able to find out easily yourself how the matrix is organized. Put known values for the X, Y, Z rotations and then dump the matrix and see where they are.Wed, 14 Jan 2015 02:14:35 GMTJeff-Kesselman