master af26a1a84715 cached
116 files
425.4 KB
128.1k tokens
514 symbols
1 requests
Download .txt
Showing preview only (458K chars total). Download the full file or copy to clipboard to get everything.
Repository: Scrawk/2D-Deformable-body-in-Unity
Branch: master
Commit: af26a1a84715
Files: 116
Total size: 425.4 KB

Directory structure:
gitextract_fo5zd9vd/

├── .gitignore
├── Assets/
│   ├── Common/
│   │   ├── Decomposition/
│   │   │   ├── Decomposition2x2d.cs
│   │   │   ├── Decomposition2x2d.cs.meta
│   │   │   ├── Decomposition2x2f.cs
│   │   │   ├── Decomposition2x2f.cs.meta
│   │   │   ├── Decomposition3x3d.cs
│   │   │   ├── Decomposition3x3d.cs.meta
│   │   │   ├── Decomposition3x3f.cs
│   │   │   └── Decomposition3x3f.cs.meta
│   │   ├── Decomposition.meta
│   │   ├── LinearAlgebra/
│   │   │   ├── Matrix2x2d.cs
│   │   │   ├── Matrix2x2d.cs.meta
│   │   │   ├── Matrix2x2f.cs
│   │   │   ├── Matrix2x2f.cs.meta
│   │   │   ├── Matrix3x3d.cs
│   │   │   ├── Matrix3x3d.cs.meta
│   │   │   ├── Matrix3x3f.cs
│   │   │   ├── Matrix3x3f.cs.meta
│   │   │   ├── Matrix4x4d.cs
│   │   │   ├── Matrix4x4d.cs.meta
│   │   │   ├── Matrix4x4f.cs
│   │   │   ├── Matrix4x4f.cs.meta
│   │   │   ├── MatrixMxN.cs
│   │   │   ├── MatrixMxN.cs.meta
│   │   │   ├── Quaternion3d.cs
│   │   │   ├── Quaternion3d.cs.meta
│   │   │   ├── Quaternion3f.cs
│   │   │   ├── Quaternion3f.cs.meta
│   │   │   ├── Vector2d.cs
│   │   │   ├── Vector2d.cs.meta
│   │   │   ├── Vector2f.cs
│   │   │   ├── Vector2f.cs.meta
│   │   │   ├── Vector2i.cs
│   │   │   ├── Vector2i.cs.meta
│   │   │   ├── Vector3d.cs
│   │   │   ├── Vector3d.cs.meta
│   │   │   ├── Vector3f.cs
│   │   │   ├── Vector3f.cs.meta
│   │   │   ├── Vector3i.cs
│   │   │   ├── Vector3i.cs.meta
│   │   │   ├── Vector4d.cs
│   │   │   ├── Vector4d.cs.meta
│   │   │   ├── Vector4f.cs
│   │   │   ├── Vector4f.cs.meta
│   │   │   ├── Vector4i.cs
│   │   │   └── Vector4i.cs.meta
│   │   ├── LinearAlgebra.meta
│   │   ├── Mathematics/
│   │   │   ├── DMath.cs
│   │   │   ├── DMath.cs.meta
│   │   │   ├── FMath.cs
│   │   │   ├── FMath.cs.meta
│   │   │   ├── IMath.cs
│   │   │   └── IMath.cs.meta
│   │   └── Mathematics.meta
│   ├── Common.meta
│   ├── FEM2D/
│   │   ├── Demo.unity
│   │   ├── Demo.unity.meta
│   │   ├── Materials/
│   │   │   ├── TextureMaterial.mat
│   │   │   ├── TextureMaterial.mat.meta
│   │   │   ├── TextureShader.shader
│   │   │   └── TextureShader.shader.meta
│   │   ├── Materials.meta
│   │   ├── Scripts/
│   │   │   ├── CreateCantileverBeam.cs
│   │   │   ├── CreateCantileverBeam.cs.meta
│   │   │   ├── CreateFromImage.cs
│   │   │   ├── CreateFromImage.cs.meta
│   │   │   ├── CreateRandomConvex.cs
│   │   │   ├── CreateRandomConvex.cs.meta
│   │   │   ├── CreateTorus.cs
│   │   │   ├── CreateTorus.cs.meta
│   │   │   ├── DelaunayTriangulation.cs
│   │   │   ├── DelaunayTriangulation.cs.meta
│   │   │   ├── FEMDemo.cs
│   │   │   ├── FEMDemo.cs.meta
│   │   │   ├── FEMElement.cs
│   │   │   ├── FEMElement.cs.meta
│   │   │   ├── FEMFractureEvent.cs
│   │   │   ├── FEMFractureEvent.cs.meta
│   │   │   ├── FEMParticle.cs
│   │   │   ├── FEMParticle.cs.meta
│   │   │   ├── FEMScene.cs
│   │   │   ├── FEMScene.cs.meta
│   │   │   ├── Mesher.cs
│   │   │   ├── Mesher.cs.meta
│   │   │   ├── Triangle.cs
│   │   │   └── Triangle.cs.meta
│   │   ├── Scripts.meta
│   │   ├── Textures/
│   │   │   ├── armadillo.png.meta
│   │   │   ├── bunny.png.meta
│   │   │   └── donut1.png.meta
│   │   └── Textures.meta
│   └── FEM2D.meta
├── LICENSE
├── Packages/
│   ├── manifest.json
│   └── packages-lock.json
├── ProjectSettings/
│   ├── AudioManager.asset
│   ├── ClusterInputManager.asset
│   ├── DynamicsManager.asset
│   ├── EditorBuildSettings.asset
│   ├── EditorSettings.asset
│   ├── GraphicsSettings.asset
│   ├── InputManager.asset
│   ├── NavMeshAreas.asset
│   ├── PackageManagerSettings.asset
│   ├── Physics2DSettings.asset
│   ├── PresetManager.asset
│   ├── ProjectSettings.asset
│   ├── ProjectVersion.txt
│   ├── QualitySettings.asset
│   ├── TagManager.asset
│   ├── TimeManager.asset
│   ├── UnityConnectSettings.asset
│   ├── VFXManager.asset
│   ├── VersionControlSettings.asset
│   └── XRSettings.asset
└── README.md

================================================
FILE CONTENTS
================================================

================================================
FILE: .gitignore
================================================
################################################################################
# This .gitignore file was automatically created by Microsoft(R) Visual Studio.
################################################################################

/Temp
/.vs/2D-Deformable-body-in-Unity/v16
/Library
/Logs
/obj/Debug


================================================
FILE: Assets/Common/Decomposition/Decomposition2x2d.cs
================================================
using System;
using System.Collections.Generic;

using Common.Core.LinearAlgebra;

namespace Common.Mathematics.Decomposition
{
    public static class Decomposition2x2d
    {

        public static Matrix2x2d QRDecomposition(Matrix2x2d m)
        {
            Vector2d a = m.GetColumn(0).Normalized;
            Matrix2x2d q = new Matrix2x2d();

            q.SetColumn(0, a);
            q.SetColumn(1, a.PerpendicularCCW);

            return q;
        }

        public static Matrix2x2d PolarDecomposition(Matrix2x2d m)
        {
            Matrix2x2d q = m + new Matrix2x2d(m.m11, -m.m10, -m.m01, m.m00);

            Vector2d c0 = q.GetColumn(0);
            Vector2d c1 = q.GetColumn(1);

            double s = c0.Magnitude;
            q.SetColumn(0, c0 / s);
            q.SetColumn(1, c1 / s);

            return q;
        }

        public static void EigenDecomposition(Matrix2x2d m, out double e1, out double e2)
        {
            // solve the characteristic polynomial
            double a = 1.0;
            double b = -(m.m00 + m.m11);
            double c = m.m00 * m.m11 - m.m01 * m.m10;

            SolveQuadratic(a, b, c, out e1, out e2);
        }

        private static bool SolveQuadratic(double a, double b, double c, out double min, out double max)
        {
            min = max = 0.0;

            if (a == 0.0 && b == 0.0)
                return true;

            double discriminant = b * b - 4.0 * a * c;

            if (discriminant < 0.0)
                return false;

            // numerical receipes 5.6 (this method ensures numerical accuracy is preserved)
            double t = -0.5 * (b + Math.Sign(b) * Math.Sqrt(discriminant));
            min = t / a;
            max = c / t;

            if (min > max)
            {
                double tmp = min;
                min = max;
                max = tmp;
            }

            return true;
        }
    }
}


================================================
FILE: Assets/Common/Decomposition/Decomposition2x2d.cs.meta
================================================
fileFormatVersion: 2
guid: 60689437f1f73d04da8380919053e6e8
timeCreated: 1514536270
licenseType: Free
MonoImporter:
  externalObjects: {}
  serializedVersion: 2
  defaultReferences: []
  executionOrder: 0
  icon: {instanceID: 0}
  userData: 
  assetBundleName: 
  assetBundleVariant: 


================================================
FILE: Assets/Common/Decomposition/Decomposition2x2f.cs
================================================
using System;
using System.Collections.Generic;

using Common.Core.LinearAlgebra;

namespace Common.Mathematics.Decomposition
{
    public static class Decomposition2x2f
    {

        public static Matrix2x2f QRDecomposition(Matrix2x2f m)
        {
            Vector2f a = m.GetColumn(0).Normalized;
            Matrix2x2f q = new Matrix2x2f();

            q.SetColumn(0, a);
            q.SetColumn(1, a.PerpendicularCCW);

            return q;
        }

        public static Matrix2x2f PolarDecomposition(Matrix2x2f m)
        {
            Matrix2x2f q = m + new Matrix2x2f(m.m11, -m.m10, -m.m01, m.m00);

            Vector2f c0 = q.GetColumn(0);
            Vector2f c1 = q.GetColumn(1);

            float s = c0.Magnitude;
            q.SetColumn(0, c0 / s);
            q.SetColumn(1, c1 / s);

            return q;
        }

        public static void EigenDecomposition(Matrix2x2f m, out float e1, out float e2)
        {
            // solve the characteristic polynomial
            float a = 1.0f;
            float b = -(m.m00 + m.m11);
            float c = m.m00 * m.m11 - m.m01 * m.m10;

            SolveQuadratic(a, b, c, out e1, out e2);
        }

        private static bool SolveQuadratic(float a, float b, float c, out float min, out float max)
        {
            min = max = 0.0f;

            if (a == 0.0f && b == 0.0f)
                return true;

            float discriminant = b * b - 4.0f * a * c;

            if (discriminant < 0.0f)
                return false;

            // numerical receipes 5.6 (this method ensures numerical accuracy is preserved)
            float t = (float)(-0.5 * (b + Math.Sign(b) * Math.Sqrt(discriminant)));
            min = t / a;
            max = c / t;

            if (min > max)
            {
                float tmp = min;
                min = max;
                max = tmp;
            }

            return true;
        }
    }
}


================================================
FILE: Assets/Common/Decomposition/Decomposition2x2f.cs.meta
================================================
fileFormatVersion: 2
guid: 677436b12b96e754eb23bb58733959f9
timeCreated: 1514536270
licenseType: Free
MonoImporter:
  externalObjects: {}
  serializedVersion: 2
  defaultReferences: []
  executionOrder: 0
  icon: {instanceID: 0}
  userData: 
  assetBundleName: 
  assetBundleVariant: 


================================================
FILE: Assets/Common/Decomposition/Decomposition3x3d.cs
================================================
using System;

using Common.Core.LinearAlgebra;

namespace Common.Mathematics.Decomposition
{

    public static class Decomposition3x3d
    {
        /// <summary>
        /// Rotates A through phi in pq-plane to set A(p,q) = 0
	    /// Rotation stored in R whose columns are eigenvectors of A
        /// </summary>
        public static void JacobiRotate(ref Matrix3x3d A, ref Matrix3x3d R, int p, int q)
        {

            if (A[p, q] == 0.0f)
                return;

            double d = (A[p, p] - A[q, q]) / (2.0f * A[p, q]);
            double t = 1.0 / (Math.Abs(d) + Math.Sqrt(d * d + 1.0));
            if (d < 0.0f) t = -t;
            double c = 1.0 / Math.Sqrt(t * t + 1);
            double s = t * c;

            A[p, p] += t * A[p, q];
            A[q, q] -= t * A[p, q];
            A[p, q] = A[q, p] = 0.0f;

            // transform A
            int k;
            for (k = 0; k < 3; k++)
            {
                if (k != p && k != q)
                {
                    double Akp = c * A[k, p] + s * A[k, q];
                    double Akq = -s * A[k, p] + c * A[k, q];
                    A[k, p] = A[p, k] = Akp;
                    A[k, q] = A[q, k] = Akq;
                }
            }

            // store rotation in R
            for (k = 0; k < 3; k++)
            {
                double Rkp = c * R[k, p] + s * R[k, q];
                double Rkq = -s * R[k, p] + c * R[k, q];
                R[k, p] = Rkp;
                R[k, q] = Rkq;
            }
        }

        public static void EigenDecomposition(Matrix3x3d A, out Matrix3x3d eigenVecs, out Vector3d eigenVals)
        {

            const int numJacobiIterations = 10;
            const double epsilon = 1e-15;

            Matrix3x3d D = A;

            // only for symmetric matrices!
            eigenVecs = Matrix3x3d.Identity;    // unit matrix
            int iter = 0;

            while (iter < numJacobiIterations)
            {
                // 3 off diagonal elements
                // find off diagonal element with maximum modulus
                int p, q;
                double a, max;
                max = Math.Abs(D.m01);
                p = 0; q = 1;
                a = Math.Abs(D.m02);
                if (a > max) { p = 0; q = 2; max = a; }
                a = Math.Abs(D.m12);
                if (a > max) { p = 1; q = 2; max = a; }
                // all small enough -> done
                if (max < epsilon) break;
                // rotate matrix with respect to that element
                JacobiRotate(ref D, ref eigenVecs, p, q);
                iter++;
            }

            eigenVals = new Vector3d(D.m00, D.m11, D.m22);
        }

        /// <summary>
        /// Perform polar decomposition A = (U D U^T) R
        /// </summary>
        public static void PolarDecomposition(Matrix3x3d A, out Matrix3x3d R, out Matrix3x3d U, out Matrix3x3d D)
        {
            // A = SR, where S is symmetric and R is orthonormal
            // -> S = (A A^T)^(1/2)

            // A = U D U^T R

            Matrix3x3d AAT = new Matrix3x3d();
            AAT.m00 = A.m00 * A.m00 + A.m01 * A.m01 + A.m02 * A.m02;
            AAT.m11 = A.m10 * A.m10 + A.m11 * A.m11 + A.m12 * A.m12;
            AAT.m22 = A.m20 * A.m20 + A.m21 * A.m21 + A.m22 * A.m22;

            AAT.m01 = A.m00 * A.m10 + A.m01 * A.m11 + A.m02 * A.m12;
            AAT.m02 = A.m00 * A.m20 + A.m01 * A.m21 + A.m02 * A.m22;
            AAT.m12 = A.m10 * A.m20 + A.m11 * A.m21 + A.m12 * A.m22;

            AAT.m10 = AAT.m01;
            AAT.m20 = AAT.m02;
            AAT.m21 = AAT.m12;

            R = Matrix3x3d.Identity;
            Vector3d eigenVals;
            EigenDecomposition(AAT, out U, out eigenVals);

            double d0 = Math.Sqrt(eigenVals.x);
            double d1 = Math.Sqrt(eigenVals.y);
            double d2 = Math.Sqrt(eigenVals.z);

            D = new Matrix3x3d();
            D.m00 = d0;
            D.m11 = d1;
            D.m22 = d2;

            const double eps = 1e-15;

            double l0 = eigenVals.x; if (l0 <= eps) l0 = 0.0; else l0 = 1.0 / d0;
            double l1 = eigenVals.y; if (l1 <= eps) l1 = 0.0; else l1 = 1.0 / d1;
            double l2 = eigenVals.z; if (l2 <= eps) l2 = 0.0; else l2 = 1.0 / d2;

            Matrix3x3d S1 = new Matrix3x3d();
            S1.m00 = l0 * U.m00 * U.m00 + l1 * U.m01 * U.m01 + l2 * U.m02 * U.m02;
            S1.m11 = l0 * U.m10 * U.m10 + l1 * U.m11 * U.m11 + l2 * U.m12 * U.m12;
            S1.m22 = l0 * U.m20 * U.m20 + l1 * U.m21 * U.m21 + l2 * U.m22 * U.m22;

            S1.m01 = l0 * U.m00 * U.m10 + l1 * U.m01 * U.m11 + l2 * U.m02 * U.m12;
            S1.m02 = l0 * U.m00 * U.m20 + l1 * U.m01 * U.m21 + l2 * U.m02 * U.m22;
            S1.m12 = l0 * U.m10 * U.m20 + l1 * U.m11 * U.m21 + l2 * U.m12 * U.m22;

            S1.m10 = S1.m01;
            S1.m20 = S1.m02;
            S1.m21 = S1.m12;

            R = S1 * A;

            // stabilize
            Vector3d c0, c1, c2;
            c0 = R.GetColumn(0);
            c1 = R.GetColumn(1);
            c2 = R.GetColumn(2);

            if (c0.SqrMagnitude < eps)
                c0 = c1.Cross(c2);
            else if (c1.SqrMagnitude < eps)
                c1 = c2.Cross(c0);
            else
                c2 = c0.Cross(c1);

            R.SetColumn(0, c0);
            R.SetColumn(1, c1);
            R.SetColumn(2, c2);
        }

        /// <summary>
        /// Return the one norm of the matrix.
        /// </summary>
        public static double OneNorm(Matrix3x3d A)
        {
            double sum1 = Math.Abs(A.m00) + Math.Abs(A.m10) + Math.Abs(A.m20);
            double sum2 = Math.Abs(A.m01) + Math.Abs(A.m11) + Math.Abs(A.m21);
            double sum3 = Math.Abs(A.m02) + Math.Abs(A.m12) + Math.Abs(A.m22);

            double maxSum = sum1;

            if (sum2 > maxSum)
                maxSum = sum2;
            if (sum3 > maxSum)
                maxSum = sum3;

            return maxSum;
        }

        /// <summary>
        /// Return the inf norm of the matrix.
        /// </summary>
        public static double InfNorm(Matrix3x3d A)
        {
            double sum1 = Math.Abs(A.m00) + Math.Abs(A.m01) + Math.Abs(A.m02);
            double sum2 = Math.Abs(A.m10) + Math.Abs(A.m11) + Math.Abs(A.m12);
            double sum3 = Math.Abs(A.m20) + Math.Abs(A.m21) + Math.Abs(A.m22);

            double maxSum = sum1;

            if (sum2 > maxSum)
                maxSum = sum2;
            if (sum3 > maxSum)
                maxSum = sum3;

            return maxSum;
        }

        /// <summary>
        /// Perform a polar decomposition of matrix M and return the rotation matrix R. This method handles the degenerated cases.
        /// </summary>am>
        public static void PolarDecompositionStable(Matrix3x3d M, double tolerance, out Matrix3x3d R)
        {
            Matrix3x3d Mt = M.Transpose;
            double Mone = OneNorm(M);
            double Minf = InfNorm(M);
            double Eone;
            Matrix3x3d MadjTt = new Matrix3x3d();
            Matrix3x3d Et = new Matrix3x3d();

            const double eps = 1.0e-15;

            do
            {
                MadjTt.SetRow(0, Mt.GetRow(1).Cross(Mt.GetRow(2)));
                MadjTt.SetRow(1, Mt.GetRow(2).Cross(Mt.GetRow(0)));
                MadjTt.SetRow(2, Mt.GetRow(0).Cross(Mt.GetRow(1)));

                double det = Mt.m00 * MadjTt.m00 + Mt.m01 * MadjTt.m01 + Mt.m02 * MadjTt.m02;

                if (Math.Abs(det) < eps)
                {
                    int index = int.MaxValue;
                    for (int i = 0; i < 3; i++)
                    {
                        double len = MadjTt.GetRow(i).SqrMagnitude;
                        if (len > eps)
                        {
                            // index of valid cross product
                            // => is also the index of the vector in Mt that must be exchanged
                            index = i;
                            break;
                        }
                    }

                    if (index == int.MaxValue)
                    {
                        R = Matrix3x3d.Identity;
                        return;
                    }
                    else
                    {

                        Mt.SetRow(index, Mt.GetRow((index + 1) % 3).Cross(Mt.GetRow((index + 2) % 3)));
                        MadjTt.SetRow((index + 1) % 3, Mt.GetRow((index + 2) % 3).Cross(Mt.GetRow(index)));
                        MadjTt.SetRow((index + 2) % 3, Mt.GetRow(index).Cross(Mt.GetRow((index + 1) % 3)));
                        Matrix3x3d M2 = Mt.Transpose;

                        Mone = OneNorm(M2);
                        Minf = InfNorm(M2);

                        det = Mt.m00 * MadjTt.m00 + Mt.m01 * MadjTt.m01 + Mt.m02 * MadjTt.m02;
                    }
                }

                double MadjTone = OneNorm(MadjTt);
                double MadjTinf = InfNorm(MadjTt);

                double gamma = Math.Sqrt(Math.Sqrt((MadjTone * MadjTinf) / (Mone * Minf)) / Math.Abs(det));

                double g1 = gamma * 0.5;
                double g2 = 0.5 / (gamma * det);

                for (int i = 0; i < 3; i++)
                {
                    for (int j = 0; j < 3; j++)
                    {
                        Et[i, j] = Mt[i, j];
                        Mt[i, j] = g1 * Mt[i, j] + g2 * MadjTt[i, j];
                        Et[i, j] -= Mt[i, j];
                    }
                }

                Eone = OneNorm(Et);

                Mone = OneNorm(Mt);
                Minf = InfNorm(Mt);
            }
            while (Eone > Mone * tolerance);

            // Q = Mt^T 
            R = Mt.Transpose;

            //end of function
        }


        /// <summary>
        /// Perform a singular value decomposition of matrix A: A = U * sigma * V^T.
        /// This function returns two proper rotation matrices U and V^T which do not 
        /// contain a reflection. Reflections are corrected by the inversion handling
        /// proposed by Irving et al. 2004.
        /// </summary>
        public static void SVDWithInversionHandling(Matrix3x3d A, out Vector3d sigma, out Matrix3x3d U, out Matrix3x3d VT)
        {

            Vector3d S;
            Matrix3x3d AT_A, V;

            AT_A = A.Transpose * A;

            // Eigen decomposition of A^T * A
            EigenDecomposition(AT_A, out V, out S);
            int pos;
            // Detect if V is a reflection .
            // Make a rotation out of it by multiplying one column with -1.
            double detV = V.Determinant;
            if (detV < 0.0f)
            {
                double minLambda = double.PositiveInfinity;
                pos = 0;
                for (int l = 0; l < 3; l++)
                {
                    if (S[l] < minLambda)
                    {
                        pos = l;
                        minLambda = S[l];
                    }
                }
                V[0, pos] = -V[0, pos];
                V[1, pos] = -V[1, pos];
                V[2, pos] = -V[2, pos];
            }

            if (S.x < 0.0f) S.x = 0.0f;     // safety for sqrt
            if (S.y < 0.0f) S.y = 0.0f;
            if (S.z < 0.0f) S.z = 0.0f;

            sigma.x = Math.Sqrt(S.x);
            sigma.y = Math.Sqrt(S.y);
            sigma.z = Math.Sqrt(S.z);

            VT = V.Transpose;

            // Check for values of hatF near zero
            int chk = 0;
            pos = 0;
            for (int l = 0; l < 3; l++)
            {
                if (Math.Abs(sigma[l]) < 1.0e-4)
                {
                    pos = l;
                    chk++;
                }
            }

            if (chk > 0)
            {

                if (chk > 1)
                {
                    U = Matrix3x3d.Identity;
                }
                else
                {
                    U = A * V;
                    for (int l = 0; l < 3; l++)
                    {
                        if (l != pos)
                        {
                            for (int m = 0; m < 3; m++)
                            {
                                U[m, l] *= 1.0f / sigma[l];

                            }
                        }
                    }

                    Vector3d[] v = new Vector3d[2];
                    int index = 0;
                    for (int l = 0; l < 3; l++)
                    {
                        if (l != pos)
                        {
                            v[index++] = new Vector3d(U[0, l], U[1, l], U[2, l]);
                        }
                    }

                    Vector3d vec = v[0].Cross(v[1]);
                    vec.Normalize();
                    U[0, pos] = vec[0];
                    U[1, pos] = vec[1];
                    U[2, pos] = vec[2];
                }

            }
            else
            {
                Vector3d sigmaInv = new Vector3d(1.0 / sigma.x, 1.0 / sigma.y, 1.0 / sigma.z);

                U = A * V;
                for (int l = 0; l < 3; l++)
                {
                    for (int m = 0; m < 3; m++)
                    {
                        U[m, l] *= sigmaInv[l];
                    }
                }
            }

            double detU = U.Determinant;

            // U is a reflection => inversion
            if (detU < 0.0)
            {
                //std::cout << "Inversion!\n";
                double minLambda = double.PositiveInfinity;
                pos = 0;
                for (int l = 0; l < 3; l++)
                {
                    if (sigma[l] < minLambda)
                    {
                        pos = l;
                        minLambda = sigma[l];
                    }
                }

                // invert values of smallest singular value
                sigma[pos] = -sigma[pos];
                U[0, pos] = -U[0, pos];
                U[1, pos] = -U[1, pos];
                U[2, pos] = -U[2, pos];
            }

            //end of function
        }

    }

}

================================================
FILE: Assets/Common/Decomposition/Decomposition3x3d.cs.meta
================================================
fileFormatVersion: 2
guid: 4c6eedd17e5c16345a731cb65b62ab3c
timeCreated: 1514536270
licenseType: Free
MonoImporter:
  externalObjects: {}
  serializedVersion: 2
  defaultReferences: []
  executionOrder: 0
  icon: {instanceID: 0}
  userData: 
  assetBundleName: 
  assetBundleVariant: 


================================================
FILE: Assets/Common/Decomposition/Decomposition3x3f.cs
================================================
using System;

using Common.Core.LinearAlgebra;

namespace Common.Mathematics.Decomposition
{

    public static class Decomposition3x3f
    {
        /// <summary>
        /// Rotates A through phi in pq-plane to set A(p,q) = 0
	    /// Rotation stored in R whose columns are eigenvectors of A
        /// </summary>
        public static void JacobiRotate(ref Matrix3x3f A, ref Matrix3x3f R, int p, int q)
        {

	        if (A[p, q] == 0.0f)
		        return;

	        float d = (A[p, p] - A[q, q]) / (2.0f*A[p, q]);
	        float t = 1.0f / (Math.Abs(d) + (float)Math.Sqrt(d*d + 1.0f));
	        if (d < 0.0f) t = -t;
	        float c = 1.0f / (float)Math.Sqrt(t*t + 1);
	        float s = t*c;

	        A[p, p] += t*A[p, q];
	        A[q, q] -= t*A[p, q];
	        A[p, q] = A[q, p] = 0.0f;

	        // transform A
	        int k;
	        for (k = 0; k < 3; k++) 
            {
		        if (k != p && k != q) 
                {
			        float Akp = c*A[k, p] + s*A[k, q];
			        float Akq = -s*A[k, p] + c*A[k, q];
			        A[k, p] = A[p, k] = Akp;
			        A[k, q] = A[q, k] = Akq;
		        }
	        }

	        // store rotation in R
	        for (k = 0; k < 3; k++) 
            {
		        float Rkp = c*R[k, p] + s*R[k, q];
		        float Rkq = -s*R[k, p] + c*R[k, q];
		        R[k, p] = Rkp;
		        R[k, q] = Rkq;
	        }
        }

        public static void EigenDecomposition(Matrix3x3f A, out Matrix3x3f eigenVecs, out Vector3f eigenVals)
        {

	        const int numJacobiIterations = 10;
	        const float epsilon = 1e-15f;

	        Matrix3x3f D = A;

	        // only for symmetric matrices!
	        eigenVecs = Matrix3x3f.Identity;	// unit matrix
	        int iter = 0;

	        while (iter < numJacobiIterations) 
            {	
                // 3 off diagonal elements
		        // find off diagonal element with maximum modulus
		        int p, q;
		        float a, max;
		        max = Math.Abs(D.m01);
		        p = 0; q = 1;
		        a = Math.Abs(D.m02);
		        if (a > max) { p = 0; q = 2; max = a; }
		        a = Math.Abs(D.m12);
		        if (a > max) { p = 1; q = 2; max = a; }
		        // all small enough -> done
		        if (max < epsilon) break;
		        // rotate matrix with respect to that element
		        JacobiRotate(ref D, ref eigenVecs, p, q);
		        iter++;
	        }

	        eigenVals = new Vector3f(D.m00, D.m11, D.m22);
        }

        /// <summary>
        /// Perform polar decomposition A = (U D U^T) R
        /// </summary>
        public static void PolarDecomposition(Matrix3x3f A, out Matrix3x3f R, out Matrix3x3f U, out Matrix3x3f D)
        {
	        // A = SR, where S is symmetric and R is orthonormal
	        // -> S = (A A^T)^(1/2)

	        // A = U D U^T R

	        Matrix3x3f AAT = new Matrix3x3f();
	        AAT.m00 = A.m00*A.m00 + A.m01*A.m01 + A.m02*A.m02;
	        AAT.m11 = A.m10*A.m10 + A.m11*A.m11 + A.m12*A.m12;
	        AAT.m22 = A.m20*A.m20 + A.m21*A.m21 + A.m22*A.m22;

	        AAT.m01 = A.m00*A.m10 + A.m01*A.m11 + A.m02*A.m12;
	        AAT.m02 = A.m00*A.m20 + A.m01*A.m21 + A.m02*A.m22;
	        AAT.m12 = A.m10*A.m20 + A.m11*A.m21 + A.m12*A.m22;

	        AAT.m10 = AAT.m01;
	        AAT.m20 = AAT.m02;
	        AAT.m21 = AAT.m12;

	        R = Matrix3x3f.Identity;
	        Vector3f eigenVals;
	        EigenDecomposition(AAT, out U, out eigenVals);

	        float d0 = (float)Math.Sqrt(eigenVals.x);
	        float d1 = (float)Math.Sqrt(eigenVals.y);
	        float d2 = (float)Math.Sqrt(eigenVals.z);

	        D = new Matrix3x3f();
	        D.m00 = d0;
	        D.m11 = d1;
	        D.m22 = d2;

	        const float eps = 1e-15f;

	        float l0 = eigenVals.x; if (l0 <= eps) l0 = 0.0f; else l0 = 1.0f / d0;
	        float l1 = eigenVals.y; if (l1 <= eps) l1 = 0.0f; else l1 = 1.0f / d1;
	        float l2 = eigenVals.z; if (l2 <= eps) l2 = 0.0f; else l2 = 1.0f / d2;

	        Matrix3x3f S1 = new Matrix3x3f();
	        S1.m00 = l0*U.m00*U.m00 + l1*U.m01*U.m01 + l2*U.m02*U.m02;
	        S1.m11 = l0*U.m10*U.m10 + l1*U.m11*U.m11 + l2*U.m12*U.m12;
	        S1.m22 = l0*U.m20*U.m20 + l1*U.m21*U.m21 + l2*U.m22*U.m22;

	        S1.m01 = l0*U.m00*U.m10 + l1*U.m01*U.m11 + l2*U.m02*U.m12;
	        S1.m02 = l0*U.m00*U.m20 + l1*U.m01*U.m21 + l2*U.m02*U.m22;
	        S1.m12 = l0*U.m10*U.m20 + l1*U.m11*U.m21 + l2*U.m12*U.m22;

	        S1.m10 = S1.m01;
	        S1.m20 = S1.m02;
	        S1.m21 = S1.m12;

	        R = S1*A;

	        // stabilize
	        Vector3f c0, c1, c2;
	        c0 = R.GetColumn(0);
	        c1 = R.GetColumn(1);
	        c2 = R.GetColumn(2);

	        if (c0.SqrMagnitude < eps)
		        c0 = c1.Cross(c2);
	        else if (c1.SqrMagnitude < eps)
		        c1 = c2.Cross(c0);
	        else
		        c2 = c0.Cross(c1);

	        R.SetColumn(0, c0);
	        R.SetColumn(1, c1);
	        R.SetColumn(2, c2);
        }

        /// <summary>
        /// Return the one norm of the matrix.
        /// </summary>
        private static float OneNorm(Matrix3x3f A)
        {
	        float sum1 = Math.Abs(A.m00) + Math.Abs(A.m10) + Math.Abs(A.m20);
	        float sum2 = Math.Abs(A.m01) + Math.Abs(A.m11) + Math.Abs(A.m21);
	        float sum3 = Math.Abs(A.m02) + Math.Abs(A.m12) + Math.Abs(A.m22);

	        float maxSum = sum1;

	        if (sum2 > maxSum)
		        maxSum = sum2;
	        if (sum3 > maxSum)
		        maxSum = sum3;

	        return maxSum;
        }

        /// <summary>
        /// Return the inf norm of the matrix.
        /// </summary>
        private static float InfNorm(Matrix3x3f A)
        {
	        float sum1 = Math.Abs(A.m00) + Math.Abs(A.m01) + Math.Abs(A.m02);
	        float sum2 = Math.Abs(A.m10) + Math.Abs(A.m11) + Math.Abs(A.m12);
	        float sum3 = Math.Abs(A.m20) + Math.Abs(A.m21) + Math.Abs(A.m22);

	        float maxSum = sum1;

	        if (sum2 > maxSum)
		        maxSum = sum2;
	        if (sum3 > maxSum)
		     maxSum = sum3;

	        return maxSum;
        }

        /// <summary>
        /// Perform a polar decomposition of matrix M and return the rotation matrix R. This method handles the degenerated cases.
        /// </summary>am>
        public static void PolarDecompositionStable(Matrix3x3f M, float tolerance, out Matrix3x3f R)
        {
	        Matrix3x3f Mt = M.Transpose;
	        float Mone = OneNorm(M);
	        float Minf = InfNorm(M);
	        float Eone;
	        Matrix3x3f MadjTt = new Matrix3x3f();
			Matrix3x3f Et = new Matrix3x3f();

	        do
	        {
		        MadjTt.SetRow(0, Mt.GetRow(1).Cross(Mt.GetRow(2)));
		        MadjTt.SetRow(1, Mt.GetRow(2).Cross(Mt.GetRow(0)));
		        MadjTt.SetRow(2, Mt.GetRow(0).Cross(Mt.GetRow(1)));

		        float det = Mt.m00 * MadjTt.m00 + Mt.m01 * MadjTt.m01 + Mt.m02 * MadjTt.m02;

		        if (Math.Abs(det) < 1.0e-12f)
		        {
			        int index = int.MaxValue;
			        for (int i = 0; i < 3; i++)
			        {
				        float len = MadjTt.GetRow(i).SqrMagnitude;
				        if (len > 1.0e-12f)
				        {
					        // index of valid cross product
					        // => is also the index of the vector in Mt that must be exchanged
					        index = i;
					        break;
				        }
			        }

			        if (index == int.MaxValue)
			        {
				        R = Matrix3x3f.Identity;
				        return;
			        }
			        else
			        {
	
                        Mt.SetRow(index, Mt.GetRow((index + 1) % 3).Cross(Mt.GetRow((index + 2) % 3)));
				        MadjTt.SetRow((index + 1) % 3, Mt.GetRow((index + 2) % 3).Cross(Mt.GetRow(index)));
				        MadjTt.SetRow((index + 2) % 3, Mt.GetRow(index).Cross(Mt.GetRow((index + 1) % 3)));
				        Matrix3x3f M2 = Mt.Transpose;

				        Mone = OneNorm(M2);
				        Minf = InfNorm(M2);

				        det = Mt.m00 * MadjTt.m00 + Mt.m01 * MadjTt.m01 + Mt.m02 * MadjTt.m02;
			        }
		        }

		        float MadjTone = OneNorm(MadjTt);
		        float MadjTinf = InfNorm(MadjTt);

		        float gamma = (float)Math.Sqrt(Math.Sqrt((MadjTone*MadjTinf) / (Mone*Minf)) / Math.Abs(det));

		        float g1 = gamma*0.5f;
		        float g2 = 0.5f / (gamma*det);

		        for(int i = 0; i < 3; i++)
		        {
			        for(int j = 0; j < 3; j++)
			        {
				        Et[i,j] = Mt[i,j];
				        Mt[i,j] = g1*Mt[i,j] + g2*MadjTt[i,j];
				        Et[i,j] -= Mt[i,j];
			        }
		        }

		        Eone = OneNorm(Et);

		        Mone = OneNorm(Mt);
		        Minf = InfNorm(Mt);
	        } 
            while (Eone > Mone * tolerance);

	        // Q = Mt^T 
	        R = Mt.Transpose;

            //end of function
        }


        /// <summary>
        /// Perform a singular value decomposition of matrix A: A = U * sigma * V^T.
        /// This function returns two proper rotation matrices U and V^T which do not 
        /// contain a reflection. Reflections are corrected by the inversion handling
        /// proposed by Irving et al. 2004.
        /// </summary>
        public static void SVDWithInversionHandling(Matrix3x3f A, out Vector3f sigma, out Matrix3x3f U, out Matrix3x3f VT)
        {

            Vector3f S;
	        Matrix3x3f AT_A, V;

	        AT_A = A.Transpose * A;

	        // Eigen decomposition of A^T * A
	        EigenDecomposition(AT_A, out V, out S);
			int pos;
	        // Detect if V is a reflection .
	        // Make a rotation out of it by multiplying one column with -1.
	        float detV = V.Determinant;
	        if (detV < 0.0f)
	        {
		        float minLambda = float.PositiveInfinity;
		        pos = 0;
		        for (int l = 0; l < 3; l++)
		        {
			        if (S[l] < minLambda)
			        {
				        pos = l;
				        minLambda = S[l];
			        }
		        }
		        V[0, pos] = -V[0, pos];
		        V[1, pos] = -V[1, pos];
		        V[2, pos] = -V[2, pos];
	        }

	        if (S.x < 0.0f) S.x = 0.0f;		// safety for sqrt
	        if (S.y < 0.0f) S.y = 0.0f;
	        if (S.z < 0.0f) S.z = 0.0f;

	        sigma.x = (float)Math.Sqrt(S.x);
	        sigma.y = (float)Math.Sqrt(S.y);
	        sigma.z = (float)Math.Sqrt(S.z);

	        VT = V.Transpose;
	     
	        // Check for values of hatF near zero
	        int chk = 0;
	        pos = 0;
	        for (int l = 0; l < 3; l++)
	        {
		        if (Math.Abs(sigma[l]) < 1.0e-4f)
		        {
			        pos = l;
			        chk++;
		        }
	        }

	        if (chk > 0)
	        {
                
		        if (chk > 1)
		        {
			        U = Matrix3x3f.Identity;
		        }
		        else
		        {
			        U = A * V;
                    for (int l = 0; l < 3; l++)
                    {
                        if (l != pos)
                        {
                            for (int m = 0; m < 3; m++)
                            {
                                U[m, l] *= 1.0f / sigma[l];

                            }
                        }
                    }

			        Vector3f[] v = new Vector3f[2];
			        int index = 0;
			        for (int l = 0; l < 3; l++)
			        {
				        if (l != pos)
				        {
					        v[index++] = new Vector3f(U[0, l], U[1, l], U[2, l]);
				        }
			        }

			        Vector3f vec = v[0].Cross(v[1]);
			        vec.Normalize();
			        U[0, pos] = vec[0];
			        U[1, pos] = vec[1];
			        U[2, pos] = vec[2];
		        }
                 
	        }
	        else
	        {
		        Vector3f sigmaInv = new Vector3f(1.0f / sigma.x, 1.0f / sigma.y, 1.0f / sigma.z);

		        U = A * V;
		        for (int l = 0; l < 3; l++)
		        {
			        for (int m = 0; m < 3; m++)
			        {
				        U[m, l] *= sigmaInv[l];
			        }
		        }
	        }

	        float detU = U.Determinant;

	        // U is a reflection => inversion
	        if (detU < 0.0f)
	        {
		        //std::cout << "Inversion!\n";
		        float minLambda = float.PositiveInfinity;
		        pos = 0;
		        for(int l = 0; l < 3; l++)
		        {
			        if (sigma[l] < minLambda)
			        {
				        pos = l;
				        minLambda = sigma[l];
			        }
		        }

		        // invert values of smallest singular value
		        sigma[pos] = -sigma[pos];
		        U[0, pos] = -U[0, pos];
		        U[1, pos] = -U[1, pos];
		        U[2, pos] = -U[2, pos];
	        }

            //end of function
        }

    }

}

================================================
FILE: Assets/Common/Decomposition/Decomposition3x3f.cs.meta
================================================
fileFormatVersion: 2
guid: c51f4ad5b0f26454b81446d12138e40d
timeCreated: 1514536270
licenseType: Free
MonoImporter:
  externalObjects: {}
  serializedVersion: 2
  defaultReferences: []
  executionOrder: 0
  icon: {instanceID: 0}
  userData: 
  assetBundleName: 
  assetBundleVariant: 


================================================
FILE: Assets/Common/Decomposition.meta
================================================
fileFormatVersion: 2
guid: ca3a86e2d1148ce4a9d75690faa7ade4
folderAsset: yes
timeCreated: 1514536270
licenseType: Free
DefaultImporter:
  externalObjects: {}
  userData: 
  assetBundleName: 
  assetBundleVariant: 


================================================
FILE: Assets/Common/LinearAlgebra/Matrix2x2d.cs
================================================
using System;
using System.Collections;
using System.Runtime.InteropServices;

using Common.Core.Mathematics;

namespace Common.Core.LinearAlgebra
{

    /// <summary>
    /// A single precision 2 dimension matrix
    /// </summary>
    [StructLayout(LayoutKind.Sequential)]
    public struct Matrix2x2d
    {
        /// <summary>
        /// The matrix
        /// </summary>
        public double m00, m01, m10, m11;

        /// <summary>
        /// The Matrix Idenity.
        /// </summary>
        static readonly public Matrix2x2d Identity = new Matrix2x2d(1, 0, 0, 1);

        /// <summary>
        /// A matrix from the following varibles.
        /// </summary>
        public Matrix2x2d(double m00, double m01, double m10, double m11)
        {
			this.m00 = m00; this.m01 = m01;
			this.m10 = m10; this.m11 = m11;
        }

        /// <summary>
        /// A matrix from the following varibles.
        /// </summary>
        public Matrix2x2d(double v)
        {
            m00 = v; m01 = v;
            m10 = v; m11 = v;
        }

        /// <summary>
        /// A matrix copied from a array of varibles.
        /// </summary>
        public Matrix2x2d(double[,] m)
        {
            m00 = m[0,0]; m01 = m[0,1];
            m10 = m[1,0]; m11 = m[1,1];
        }

		/// <summary>
		/// A matrix copied from a array of varibles.
		/// </summary>
		public Matrix2x2d(double[] m)
		{
            m00 = m[0 + 0 * 2]; m01 = m[0 + 1 * 2];
            m10 = m[1 + 0 * 2]; m11 = m[1 + 1 * 2];
		}

        /// <summary>
        /// Access the varible at index i
        /// </summary>
        public double this[int i]
        {
            get
            {
                switch (i)
                {
                    case 0: return m00;
                    case 1: return m10;
                    case 2: return m01;
                    case 3: return m11;
                    default: throw new IndexOutOfRangeException("Matrix2x2d index out of range: " + i);
                }
            }
            set
            {
                switch (i)
                {
                    case 0: m00 = value; break;
                    case 1: m10 = value; break;
                    case 2: m01 = value; break;
                    case 3: m11 = value; break;
                    default: throw new IndexOutOfRangeException("Matrix2x2d index out of range: " + i);
                }
            }
        }

        /// <summary>
        /// Access the varible at index i,j.
        /// </summary>
        public double this[int i, int j]
        {
            get
            {
                int k = i + j * 2;
                switch (k)
                {
                    case 0: return m00;
                    case 1: return m10;
                    case 2: return m01;
                    case 3: return m11;
                    default: throw new IndexOutOfRangeException("Matrix2x2d index out of range: " + k);
                }
            }
            set
            {
                int k = i + j * 2;
                switch (k)
                {
                    case 0: m00 = value; break;
                    case 1: m10 = value; break;
                    case 2: m01 = value; break;
                    case 3: m11 = value; break;
                    default: throw new IndexOutOfRangeException("Matrix2x2d index out of range: " + k);
                }
            }
        }

        /// <summary>
        /// The transpose of the matrix. The rows and columns are flipped.
        /// </summary>
        public Matrix2x2d Transpose
        {
            get
            {
                Matrix2x2d kTranspose = new Matrix2x2d();
                kTranspose.m00 = m00;
                kTranspose.m10 = m01;
                kTranspose.m01 = m10;
                kTranspose.m11 = m11;

                return kTranspose;
            }
        }

        /// <summary>
        /// The determinate of a matrix. 
        /// </summary>
        public double Determinant
        {
            get
            {
                return m00 * m11 - m10 * m01;
            }
        }

        /// <summary>
        /// The inverse of the matrix.
        /// A matrix multipled by its inverse is the idenity.
        /// </summary>
        public Matrix2x2d Inverse
        {
            get
            {
                Matrix2x2d kInverse = Identity;
                TryInverse(ref kInverse);
                return kInverse;
            }
        }

        public double Trace
        {
            get
            {
                return m00 + m11;
            }
        }

        /// <summary>
        /// Add two matrices.
        /// </summary>
        public static Matrix2x2d operator +(Matrix2x2d m1, Matrix2x2d m2)
        {
            Matrix2x2d kSum = new Matrix2x2d();
            kSum.m00 = m1.m00 + m2.m00;
            kSum.m10 = m1.m10 + m2.m10;
            kSum.m01 = m1.m01 + m2.m01;
            kSum.m11 = m1.m11 + m2.m11;

            return kSum;
        }

        /// <summary>
        /// Subtract two matrices.
        /// </summary>
        public static Matrix2x2d operator -(Matrix2x2d m1, Matrix2x2d m2)
        {
            Matrix2x2d kSum = new Matrix2x2d();
            kSum.m00 = m1.m00 - m2.m00;
            kSum.m10 = m1.m10 - m2.m10;
            kSum.m01 = m1.m01 - m2.m01;
            kSum.m11 = m1.m11 - m2.m11;
            return kSum;
        }

        /// <summary>
        /// Multiply two matrices.
        /// </summary>
        public static Matrix2x2d operator *(Matrix2x2d m1, Matrix2x2d m2)
        {
            Matrix2x2d kProd = new Matrix2x2d();
            kProd.m00 = m1.m00 * m2.m00 + m1.m01 * m2.m10;
            kProd.m10 = m1.m10 * m2.m00 + m1.m11 * m2.m10;
            kProd.m01 = m1.m00 * m2.m01 + m1.m01 * m2.m11;
            kProd.m11 = m1.m10 * m2.m01 + m1.m11 * m2.m11;

            return kProd;
        }

        /// <summary>
        /// Multiply  a vector by a matrix.
        /// </summary>
        public static Vector2d operator *(Matrix2x2d m, Vector2d v)
        {
            Vector2d kProd = new Vector2d();

			kProd.x = m.m00 * v.x + m.m01 * v.y;
			kProd.y = m.m10 * v.x + m.m11 * v.y;

            return kProd;
        }

        /// <summary>
        /// Multiply a matrix by a scalar.
        /// </summary>
        public static Matrix2x2d operator *(Matrix2x2d m, double s)
        {
            Matrix2x2d kProd = new Matrix2x2d();
            kProd.m00 = m.m00 * s;
            kProd.m10 = m.m10 * s;
            kProd.m01 = m.m01 * s;
            kProd.m11 = m.m11 * s;

            return kProd;
        }

        /// <summary>
        /// Multiply a matrix by a scalar.
        /// </summary>
        public static Matrix2x2d operator *(double s, Matrix2x2d m)
        {
            Matrix2x2d kProd = new Matrix2x2d();
            kProd.m00 = m.m00 * s;
            kProd.m10 = m.m10 * s;
            kProd.m01 = m.m01 * s;
            kProd.m11 = m.m11 * s;

            return kProd;
        }

        /// <summary>
        /// Are these matrices equal.
        /// </summary>
        public static bool operator ==(Matrix2x2d m1, Matrix2x2d m2)
        {

            if (m1.m00 != m2.m00) return false;
            if (m1.m10 != m2.m10) return false;
            if (m1.m01 != m2.m01) return false;
            if (m1.m11 != m2.m11) return false;

            return true;
        }

        /// <summary>
        /// Are these matrices not equal.
        /// </summary>
        public static bool operator !=(Matrix2x2d m1, Matrix2x2d m2)
        {
            if (m1.m00 != m2.m00) return true;
            if (m1.m10 != m2.m10) return true;
            if (m1.m01 != m2.m01) return true;
            if (m1.m11 != m2.m11) return true;

            return false;
        }

		/// <summary>
		/// Are these matrices equal.
		/// </summary>
		public override bool Equals (object obj)
		{
			if(!(obj is Matrix2x2d)) return false;
			
			Matrix2x2d mat = (Matrix2x2d)obj;
			
			return this == mat;
		}

        /// <summary>
        /// Are these matrices equal.
        /// </summary>
        public bool Equals(Matrix2x2d mat)
        {
            return this == mat;
        }

        /// <summary>
        /// Are these matrices equal.
        /// </summary>
        public bool EqualsWithError(Matrix2x2d m, double eps)
        {
            if (Math.Abs(m00 - m.m00) > eps) return false;
            if (Math.Abs(m10 - m.m10) > eps) return false;
            if (Math.Abs(m01 - m.m01) > eps) return false;
            if (Math.Abs(m11 - m.m11) > eps) return false;

            return true;
        }
		
		/// <summary>
		/// Matrices hash code. 
		/// </summary>
		public override int GetHashCode()
		{
			int hash = 0;
			
			for(int i = 0; i < 4; i++)
				hash ^= this[i].GetHashCode();
			
			return hash;
		}

        /// <summary>
        /// A matrix as a string.
        /// </summary>
        public override string ToString()
        {
            return this[0, 0] + "," + this[0, 1] + "\n" + this[1, 0] + "," + this[1, 1];
        }

        /// <summary>
        /// The Inverse of the matrix copied into mInv.
        /// Returns false if the matrix has no inverse.
        /// A matrix multipled by its inverse is the idenity.
        /// </summary>
        public bool TryInverse(ref Matrix2x2d mInv)
        {
            double det = Determinant;

            if (DMath.IsZero(det))
                return false;

            double invDet = 1.0 / det;

			mInv.m00 = m11 * invDet;
			mInv.m01 = -m01 * invDet;
			mInv.m10 = -m10 * invDet;
			mInv.m11 = m00 * invDet;
            return true;
        }

        /// <summary>
        /// Get the ith column as a vector.
        /// </summary>
        public Vector2d GetColumn(int iCol)
        {
			return new Vector2d(this[0, iCol], this[1, iCol]);
        }

        /// <summary>
        /// Set the ith column from avector.
        /// </summary>
        public void SetColumn(int iCol, Vector2d v)
        {
			this[0, iCol] = v.x;
			this[1, iCol] = v.y;
        }

        /// <summary>
        /// Get the ith row as a vector.
        /// </summar
        public Vector2d GetRow(int iRow)
        {
			return new Vector2d(this[iRow, 0], this[iRow, 1]);
        }

        /// <summary>
        /// Set the ith row from avector.
        /// </summary>
        public void SetRow(int iRow, Vector2d v)
        {
			this[iRow, 0] = v.x;
			this[iRow, 1] = v.y;
        }

        /// <summary>
        /// Create a rotation out of a angle.
        /// </summary>
        static public Matrix2x2d Rotate(double angle)
        {
            double ca = Math.Cos(angle * Math.PI / 180.0);
            double sa = Math.Sin(angle * Math.PI / 180.0);

            return new Matrix2x2d(ca, -sa,
                                  sa, ca);
        }

        /// <summary>
        /// Convert to a float precision 3 dimension matrix.
        /// </summary>
        public Matrix3x3d ToMatrix3x3d()
        {
			return new Matrix3x3d(m00, m01, 0.0,
			                      m10, m11, 0.0,
                                  0.0, 0.0, 0.0);
        }

	}

}



























================================================
FILE: Assets/Common/LinearAlgebra/Matrix2x2d.cs.meta
================================================
fileFormatVersion: 2
guid: 84b9e005a3c7e82429bbb49ae4ad0119
timeCreated: 1514536270
licenseType: Free
MonoImporter:
  externalObjects: {}
  serializedVersion: 2
  defaultReferences: []
  executionOrder: 0
  icon: {instanceID: 0}
  userData: 
  assetBundleName: 
  assetBundleVariant: 


================================================
FILE: Assets/Common/LinearAlgebra/Matrix2x2f.cs
================================================
using System;
using System.Collections;
using System.Runtime.InteropServices;

using Common.Core.Mathematics;

namespace Common.Core.LinearAlgebra
{
    /// <summary>
    /// A single precision 2 dimension matrix
    /// </summary>
    [StructLayout(LayoutKind.Sequential)]
    public struct Matrix2x2f
    {
        /// <summary>
        /// The matrix
        /// </summary>
        public float m00, m10, m01, m11;

        /// <summary>
        /// The Matrix Idenity.
        /// </summary>
        static readonly public Matrix2x2f Identity = new Matrix2x2f(1, 0, 0, 1);

        /// <summary>
        /// A matrix from the following varibles.
        /// </summary>
        public Matrix2x2f(float m00, float m01, float m10, float m11)
        {
			this.m00 = m00; this.m01 = m01;
			this.m10 = m10; this.m11 = m11;
        }

        /// <summary>
        /// A matrix from the following varibles.
        /// </summary>
        public Matrix2x2f(float v)
        {
            m00 = v; m01 = v;
            m10 = v; m11 = v;
        }

        /// <summary>
        /// A matrix copied from a array of varibles.
        /// </summary>
        public Matrix2x2f(float[,] m)
        {
            m00 = m[0,0]; m01 = m[0,1];
            m10 = m[1,0]; m11 = m[1,1];
        }

		/// <summary>
		/// A matrix copied from a array of varibles.
		/// </summary>
		public Matrix2x2f(float[] m)
		{
            m00 = m[0 + 0 * 2]; m01 = m[0 + 1 * 2];
            m10 = m[1 + 0 * 2]; m11 = m[1 + 1 * 2];
		}

        /// <summary>
        /// Access the varible at index i
        /// </summary>
        public float this[int i]
        {
            get
            {
                switch (i)
                {
                    case 0: return m00;
                    case 1: return m10;
                    case 2: return m01;
                    case 3: return m11;
                    default: throw new IndexOutOfRangeException("Matrix2x2f index out of range: " + i);
                }
            }
            set
            {
                switch (i)
                {
                    case 0: m00 = value; break;
                    case 1: m10 = value; break;
                    case 2: m01 = value; break;
                    case 3: m11 = value; break;
                    default: throw new IndexOutOfRangeException("Matrix2x2f index out of range: " + i);
                }
            }
        }

        /// <summary>
        /// The transpose of the matrix. The rows and columns are flipped.
        /// </summary>
        public Matrix2x2f Transpose
        {
            get
            {
                Matrix2x2f kTranspose = new Matrix2x2f();
                kTranspose.m00 = m00;
                kTranspose.m10 = m01;
                kTranspose.m01 = m10;
                kTranspose.m11 = m11;

                return kTranspose;
            }
        }

        /// <summary>
        /// The determinate of a matrix. 
        /// </summary>
        public float Determinant
        {
            get
            {
                return m00 * m11 - m10 * m01;
            }
        }

        /// <summary>
        /// The inverse of the matrix.
        /// A matrix multipled by its inverse is the idenity.
        /// </summary>
        public Matrix2x2f Inverse
        {
            get
            {
                Matrix2x2f kInverse = Identity;
                TryInverse(ref kInverse);
                return kInverse;
            }
        }

        public float Trace
        {
            get
            {
                return m00 + m11;
            }
        }

        /// <summary>
        /// Access the varible at index i,j.
        /// </summary>
        public float this[int i, int j]
        {
            get
            {
                int k = i + j * 2;
                switch (k)
                {
                    case 0: return m00;
                    case 1: return m10;
                    case 2: return m01;
                    case 3: return m11;
                    default: throw new IndexOutOfRangeException("Matrix2x2f index out of range: " + k);
                }
            }
            set
            {
                int k = i + j * 2;
                switch (k)
                {
                    case 0: m00 = value; break;
                    case 1: m10 = value; break;
                    case 2: m01 = value; break;
                    case 3: m11 = value; break;
                    default: throw new IndexOutOfRangeException("Matrix2x2f index out of range: " + k);
                }
            }
        }

        /// <summary>
        /// Add two matrices.
        /// </summary>
        public static Matrix2x2f operator +(Matrix2x2f m1, Matrix2x2f m2)
        {
            Matrix2x2f kSum = new Matrix2x2f();
            kSum.m00 = m1.m00 + m2.m00;
            kSum.m10 = m1.m10 + m2.m10;
            kSum.m01 = m1.m01 + m2.m01;
            kSum.m11 = m1.m11 + m2.m11;

            return kSum;
        }

        /// <summary>
        /// Subtract two matrices.
        /// </summary>
        public static Matrix2x2f operator -(Matrix2x2f m1, Matrix2x2f m2)
        {
            Matrix2x2f kSum = new Matrix2x2f();
            kSum.m00 = m1.m00 - m2.m00;
            kSum.m10 = m1.m10 - m2.m10;
            kSum.m01 = m1.m01 - m2.m01;
            kSum.m11 = m1.m11 - m2.m11;
            return kSum;
        }

        /// <summary>
        /// Multiply two matrices.
        /// </summary>
        public static Matrix2x2f operator *(Matrix2x2f m1, Matrix2x2f m2)
        {
            Matrix2x2f kProd = new Matrix2x2f();
            kProd.m00 = m1.m00 * m2.m00 + m1.m01 * m2.m10;
            kProd.m10 = m1.m10 * m2.m00 + m1.m11 * m2.m10;
            kProd.m01 = m1.m00 * m2.m01 + m1.m01 * m2.m11;
            kProd.m11 = m1.m10 * m2.m01 + m1.m11 * m2.m11;

            return kProd;
        }

        /// <summary>
        /// Multiply  a vector by a matrix.
        /// </summary>
        public static Vector2f operator *(Matrix2x2f m, Vector2f v)
        {
            Vector2f kProd = new Vector2f();

			kProd.x = m.m00 * v.x + m.m01 * v.y;
			kProd.y = m.m10 * v.x + m.m11 * v.y;

            return kProd;
        }

        /// <summary>
        /// Multiply a matrix by a scalar.
        /// </summary>
        public static Matrix2x2f operator *(Matrix2x2f m, float s)
        {
            Matrix2x2f kProd = new Matrix2x2f();
            kProd.m00 = m.m00 * s;
            kProd.m10 = m.m10 * s;
            kProd.m01 = m.m01 * s;
            kProd.m11 = m.m11 * s;

            return kProd;
        }

        /// <summary>
        /// Multiply a matrix by a scalar.
        /// </summary>
        public static Matrix2x2f operator *(float s, Matrix2x2f m)
        {
            Matrix2x2f kProd = new Matrix2x2f();
            kProd.m00 = m.m00 * s;
            kProd.m10 = m.m10 * s;
            kProd.m01 = m.m01 * s;
            kProd.m11 = m.m11 * s;

            return kProd;
        }

        /// <summary>
        /// Are these matrices equal.
        /// </summary>
        public static bool operator ==(Matrix2x2f m1, Matrix2x2f m2)
        {

            if (m1.m00 != m2.m00) return false;
            if (m1.m10 != m2.m10) return false;
            if (m1.m01 != m2.m01) return false;
            if (m1.m11 != m2.m11) return false;

            return true;
        }

        /// <summary>
        /// Are these matrices not equal.
        /// </summary>
        public static bool operator !=(Matrix2x2f m1, Matrix2x2f m2)
        {
            if (m1.m00 != m2.m00) return true;
            if (m1.m10 != m2.m10) return true;
            if (m1.m01 != m2.m01) return true;
            if (m1.m11 != m2.m11) return true;

            return false;
        }

		/// <summary>
		/// Are these matrices equal.
		/// </summary>
		public override bool Equals (object obj)
		{
			if(!(obj is Matrix2x2f)) return false;
			
			Matrix2x2f mat = (Matrix2x2f)obj;
			
			return this == mat;
		}

        /// <summary>
        /// Are these matrices equal.
        /// </summary>
        public bool Equals(Matrix2x2f mat)
        {
            return this == mat;
        }

        /// <summary>
        /// Are these matrices equal.
        /// </summary>
        public bool EqualsWithError(Matrix2x2f m, float eps)
        {
            if (Math.Abs(m00 - m.m00) > eps) return false;
            if (Math.Abs(m10 - m.m10) > eps) return false;
            if (Math.Abs(m01 - m.m01) > eps) return false;
            if (Math.Abs(m11 - m.m11) > eps) return false;

            return true;
        }
		
		/// <summary>
		/// Matrices hash code. 
		/// </summary>
		public override int GetHashCode()
		{
			int hash = 0;
			
			for(int i = 0; i < 4; i++)
				hash ^= this[i].GetHashCode();
			
			return hash;
		}

        /// <summary>
        /// A matrix as a string.
        /// </summary>
        public override string ToString()
        {
            return this[0, 0] + "," + this[0, 1] + "\n" + this[1, 0] + "," + this[1, 1];
        }

        /// <summary>
        /// The Inverse of the matrix copied into mInv.
        /// Returns false if the matrix has no inverse.
        /// A matrix multipled by its inverse is the idenity.
        /// </summary>
        public bool TryInverse(ref Matrix2x2f mInv)
        {
            float det = Determinant;

            if (FMath.IsZero(det))
                return false;

            float invDet = 1.0f / det;

			mInv.m00 = m11 * invDet;
			mInv.m01 = -m01 * invDet;
			mInv.m10 = -m10 * invDet;
			mInv.m11 = m00 * invDet;
            return true;
        }

        /// <summary>
        /// Get the ith column as a vector.
        /// </summary>
        public Vector2f GetColumn(int iCol)
        {
			return new Vector2f(this[0, iCol], this[1, iCol]);
        }

        /// <summary>
        /// Set the ith column from avector.
        /// </summary>
        public void SetColumn(int iCol, Vector2f v)
        {
			this[0, iCol] = v.x;
			this[1, iCol] = v.y;
        }

        /// <summary>
        /// Get the ith row as a vector.
        /// </summary>
        public Vector2f GetRow(int iRow)
        {
			return new Vector2f(this[iRow, 0], this[iRow, 1]);
        }

        /// <summary>
        /// Set the ith row from avector.
        /// </summary>
        public void SetRow(int iRow, Vector2f v)
        {
			this[iRow, 0 ] = v.x;
			this[iRow, 1 ] = v.y;
        }

        /// <summary>
        /// Create a rotation out of a angle.
        /// </summary>
        static public Matrix2x2f Rotate(float angle)
        {
            float ca = (float)Math.Cos(angle * Math.PI / 180.0);
            float sa = (float)Math.Sin(angle * Math.PI / 180.0);

            return new Matrix2x2f(ca, -sa,
                                  sa, ca);
        }

        /// <summary>
        /// Convert to a single precision 3 dimension matrix.
        /// </summary>
        public Matrix3x3f ToMatrix3x3f()
        {
			return new Matrix3x3f(m00, m01, 0.0f,
			                      m10, m11, 0.0f,
                                  0.0f, 0.0f, 0.0f);
        }

    }

}



























================================================
FILE: Assets/Common/LinearAlgebra/Matrix2x2f.cs.meta
================================================
fileFormatVersion: 2
guid: 5552436bd5f193c4c8a224e34dc6e321
timeCreated: 1514536270
licenseType: Free
MonoImporter:
  externalObjects: {}
  serializedVersion: 2
  defaultReferences: []
  executionOrder: 0
  icon: {instanceID: 0}
  userData: 
  assetBundleName: 
  assetBundleVariant: 


================================================
FILE: Assets/Common/LinearAlgebra/Matrix3x3d.cs
================================================
using System;
using System.Collections;
using System.Runtime.InteropServices;

using Common.Core.Mathematics;

namespace Common.Core.LinearAlgebra
{
    /// <summary>
    /// A single precision 3 dimension matrix
    /// </summary>
    [StructLayout(LayoutKind.Sequential)]
    public struct Matrix3x3d
    {
        /// <summary>
        /// The matrix
        /// </summary>
        public double m00, m01, m02;
        public double m10, m11, m12;
        public double m20, m21, m22;

        /// <summary>
        /// The Matrix Idenity.
        /// </summary>
        static readonly public Matrix3x3d Identity = new Matrix3x3d(1, 0, 0, 0, 1, 0, 0, 0, 1);

        /// <summary>
        /// A matrix from the following varibles.
        /// </summary>
        public Matrix3x3d(double m00, double m01, double m02,
                          double m10, double m11, double m12,
                          double m20, double m21, double m22)
        {
            this.m00 = m00; this.m01 = m01; this.m02 = m02;
            this.m10 = m10; this.m11 = m11; this.m12 = m12;
            this.m20 = m20; this.m21 = m21; this.m22 = m22;

        }

        /// <summary>
        /// A matrix from the following varibles.
        /// </summary>
        public Matrix3x3d(double v)
        {
            m00 = v; m01 = v; m02 = v;
            m10 = v; m11 = v; m12 = v;
            m20 = v; m21 = v; m22 = v;
        }

        /// <summary>
        /// A matrix copied from a array of varibles.
        /// </summary>
        public Matrix3x3d(double[,] m)
        {
            m00 = m[0, 0]; m01 = m[0, 1]; m02 = m[0, 2];
            m10 = m[1, 0]; m11 = m[1, 1]; m12 = m[1, 2];
            m20 = m[2, 0]; m21 = m[2, 1]; m22 = m[2, 2];
        }

        /// <summary>
        /// A matrix copied from a array of varibles.
        /// </summary>
        public Matrix3x3d(double[] m)
        {
            m00 = m[0 + 0 * 3]; m01 = m[0 + 1 * 3]; m02 = m[0 + 2 * 3];
            m10 = m[1 + 0 * 3]; m11 = m[1 + 1 * 3]; m12 = m[1 + 2 * 3];
            m20 = m[2 + 0 * 3]; m21 = m[2 + 1 * 3]; m22 = m[2 + 2 * 3];
        }

        /// <summary>
        /// Access the varible at index i
        /// </summary>
        public double this[int i]
        {
            get
            {
                switch (i)
                {
                    case 0: return m00;
                    case 1: return m10;
                    case 2: return m20;
                    case 3: return m01;
                    case 4: return m11;
                    case 5: return m21;
                    case 6: return m02;
                    case 7: return m12;
                    case 8: return m22;
                    default: throw new IndexOutOfRangeException("Matrix3x3d index out of range: " + i);
                }
            }
            set
            {
                switch (i)
                {
                    case 0: m00 = value; break;
                    case 1: m10 = value; break;
                    case 2: m20 = value; break;
                    case 3: m01 = value; break;
                    case 4: m11 = value; break;
                    case 5: m21 = value; break;
                    case 6: m02 = value; break;
                    case 7: m12 = value; break;
                    case 8: m22 = value; break;
                    default: throw new IndexOutOfRangeException("Matrix3x3d index out of range: " + i);
                }
            }
        }

        /// <summary>
        /// Access the varible at index ij
        /// </summary>
        public double this[int i, int j]
        {
            get
            {
                int k = i + j * 3;
                switch (k)
                {
                    case 0: return m00;
                    case 1: return m10;
                    case 2: return m20;
                    case 3: return m01;
                    case 4: return m11;
                    case 5: return m21;
                    case 6: return m02;
                    case 7: return m12;
                    case 8: return m22;
                    default: throw new IndexOutOfRangeException("Matrix3x3d index out of range: " + k);
                }
            }
            set
            {
                int k = i + j * 3;
                switch (k)
                {
                    case 0: m00 = value; break;
                    case 1: m10 = value; break;
                    case 2: m20 = value; break;
                    case 3: m01 = value; break;
                    case 4: m11 = value; break;
                    case 5: m21 = value; break;
                    case 6: m02 = value; break;
                    case 7: m12 = value; break;
                    case 8: m22 = value; break;
                    default: throw new IndexOutOfRangeException("Matrix3x3d index out of range: " + k);
                }
            }
        }

        /// <summary>
        /// The transpose of the matrix. The rows and columns are flipped.
        /// </summary>
        public Matrix3x3d Transpose
        {
            get
            {
                Matrix3x3d transpose = new Matrix3x3d();

                transpose.m00 = m00;
                transpose.m01 = m10;
                transpose.m02 = m20;

                transpose.m10 = m01;
                transpose.m11 = m11;
                transpose.m12 = m21;

                transpose.m20 = m02;
                transpose.m21 = m12;
                transpose.m22 = m22;

                return transpose;
            }
        }

        /// <summary>
        /// The determinate of a matrix. 
        /// </summary>
        public double Determinant
        {
            get
            {
                double cofactor00 = m11 * m22 - m12 * m21;
                double cofactor10 = m12 * m20 - m10 * m22;
                double cofactor20 = m10 * m21 - m11 * m20;

                double det = m00 * cofactor00 + m01 * cofactor10 + m02 * cofactor20;

                return det;
            }
        }

        /// <summary>
        /// The inverse of the matrix.
        /// A matrix multipled by its inverse is the idenity.
        /// </summary>
        public Matrix3x3d Inverse
        {
            get
            {
                Matrix3x3d inverse = Identity;
                TryInverse(out inverse);
                return inverse;
            }
        }

        public double Trace
        {
            get
            {
                return m00 + m11 + m22;
            }
        }

        /// <summary>
        /// Add two matrices.
        /// </summary>
        public static Matrix3x3d operator +(Matrix3x3d m1, Matrix3x3d m2)
        {
            Matrix3x3d kSum = new Matrix3x3d();
            kSum.m00 = m1.m00 + m2.m00;
            kSum.m01 = m1.m01 + m2.m01;
            kSum.m02 = m1.m02 + m2.m02;

            kSum.m10 = m1.m10 + m2.m10;
            kSum.m11 = m1.m11 + m2.m11;
            kSum.m12 = m1.m12 + m2.m12;

            kSum.m20 = m1.m20 + m2.m20;
            kSum.m21 = m1.m21 + m2.m21;
            kSum.m22 = m1.m22 + m2.m22;

            return kSum;
        }

        /// <summary>
        /// Subtract two matrices.
        /// </summary>
        public static Matrix3x3d operator -(Matrix3x3d m1, Matrix3x3d m2)
        {
            Matrix3x3d kSum = new Matrix3x3d();
            kSum.m00 = m1.m00 - m2.m00;
            kSum.m01 = m1.m01 - m2.m01;
            kSum.m02 = m1.m02 - m2.m02;

            kSum.m10 = m1.m10 - m2.m10;
            kSum.m11 = m1.m11 - m2.m11;
            kSum.m12 = m1.m12 - m2.m12;

            kSum.m20 = m1.m20 - m2.m20;
            kSum.m21 = m1.m21 - m2.m21;
            kSum.m22 = m1.m22 - m2.m22;
            return kSum;
        }

        /// <summary>
        /// Multiply two matrices.
        /// </summary>
        public static Matrix3x3d operator *(Matrix3x3d m1, Matrix3x3d m2)
        {
            Matrix3x3d kProd = new Matrix3x3d();

            kProd.m00 = m1.m00 * m2.m00 + m1.m01 * m2.m10 + m1.m02 * m2.m20;
            kProd.m01 = m1.m00 * m2.m01 + m1.m01 * m2.m11 + m1.m02 * m2.m21;
            kProd.m02 = m1.m00 * m2.m02 + m1.m01 * m2.m12 + m1.m02 * m2.m22;

            kProd.m10 = m1.m10 * m2.m00 + m1.m11 * m2.m10 + m1.m12 * m2.m20;
            kProd.m11 = m1.m10 * m2.m01 + m1.m11 * m2.m11 + m1.m12 * m2.m21;
            kProd.m12 = m1.m10 * m2.m02 + m1.m11 * m2.m12 + m1.m12 * m2.m22;

            kProd.m20 = m1.m20 * m2.m00 + m1.m21 * m2.m10 + m1.m22 * m2.m20;
            kProd.m21 = m1.m20 * m2.m01 + m1.m21 * m2.m11 + m1.m22 * m2.m21;
            kProd.m22 = m1.m20 * m2.m02 + m1.m21 * m2.m12 + m1.m22 * m2.m22;

            return kProd;
        }

        /// <summary>
        /// Multiply  a vector by a matrix.
        /// </summary>
        public static Vector3d operator *(Matrix3x3d m, Vector3d v)
        {
            Vector3d kProd = new Vector3d();

            kProd.x = m.m00 * v.x + m.m01 * v.y + m.m02 * v.z;
            kProd.y = m.m10 * v.x + m.m11 * v.y + m.m12 * v.z;
            kProd.z = m.m20 * v.x + m.m21 * v.y + m.m22 * v.z;

            return kProd;
        }

        /// <summary>
        /// Multiply a matrix by a scalar.
        /// </summary>
        public static Matrix3x3d operator *(Matrix3x3d m1, double s)
        {
            Matrix3x3d kProd = new Matrix3x3d();
            kProd.m00 = m1.m00 * s;
            kProd.m01 = m1.m01 * s;
            kProd.m02 = m1.m02 * s;

            kProd.m10 = m1.m10 * s;
            kProd.m11 = m1.m11 * s;
            kProd.m12 = m1.m12 * s;

            kProd.m20 = m1.m20 * s;
            kProd.m21 = m1.m21 * s;
            kProd.m22 = m1.m22 * s;

            return kProd;
        }

        /// <summary>
        /// Multiply a matrix by a scalar.
        /// </summary>
        public static Matrix3x3d operator *(double s, Matrix3x3d m1)
        {
            Matrix3x3d kProd = new Matrix3x3d();
            kProd.m00 = m1.m00 * s;
            kProd.m01 = m1.m01 * s;
            kProd.m02 = m1.m02 * s;

            kProd.m10 = m1.m10 * s;
            kProd.m11 = m1.m11 * s;
            kProd.m12 = m1.m12 * s;

            kProd.m20 = m1.m20 * s;
            kProd.m21 = m1.m21 * s;
            kProd.m22 = m1.m22 * s;

            return kProd;
        }

        /// <summary>
        /// Are these matrices equal.
        /// </summary>
        public static bool operator ==(Matrix3x3d m1, Matrix3x3d m2)
        {

            if (m1.m00 != m2.m00) return false;
            if (m1.m01 != m2.m01) return false;
            if (m1.m02 != m2.m02) return false;

            if (m1.m10 != m2.m10) return false;
            if (m1.m11 != m2.m11) return false;
            if (m1.m12 != m2.m12) return false;

            if (m1.m20 != m2.m20) return false;
            if (m1.m21 != m2.m21) return false;
            if (m1.m22 != m2.m22) return false;

            return true;
        }

        /// <summary>
        /// Are these matrices not equal.
        /// </summary>
        public static bool operator !=(Matrix3x3d m1, Matrix3x3d m2)
        {
            if (m1.m00 != m2.m00) return true;
            if (m1.m01 != m2.m01) return true;
            if (m1.m02 != m2.m02) return true;

            if (m1.m10 != m2.m10) return true;
            if (m1.m11 != m2.m11) return true;
            if (m1.m12 != m2.m12) return true;

            if (m1.m20 != m2.m20) return true;
            if (m1.m21 != m2.m21) return true;
            if (m1.m22 != m2.m22) return true;

            return false;
        }

        /// <summary>
        /// Are these matrices equal.
        /// </summary>
        public override bool Equals(object obj)
        {
            if (!(obj is Matrix3x3d)) return false;

			Matrix3x3d mat = (Matrix3x3d)obj;

            return this == mat;
        }

        /// <summary>
        /// Are these matrices equal.
        /// </summary>
        public bool Equals(Matrix3x3d mat)
        {
            return this == mat;
        }

        /// <summary>
        /// Are these matrices equal.
        /// </summary>
        public bool EqualsWithError(Matrix3x3d m, double eps)
        {
            if (Math.Abs(m00 - m.m00) > eps) return false;
            if (Math.Abs(m10 - m.m10) > eps) return false;
            if (Math.Abs(m20 - m.m20) > eps) return false;

            if (Math.Abs(m01 - m.m01) > eps) return false;
            if (Math.Abs(m11 - m.m11) > eps) return false;
            if (Math.Abs(m21 - m.m21) > eps) return false;

            if (Math.Abs(m02 - m.m02) > eps) return false;
            if (Math.Abs(m12 - m.m12) > eps) return false;
            if (Math.Abs(m22 - m.m22) > eps) return false;

            return true;
        }

        /// <summary>
        /// Matrices hash code. 
        /// </summary>
        public override int GetHashCode()
        {
            int hash = 0;

            for (int i = 0; i < 9; i++)
                hash ^= this[i].GetHashCode();

            return hash;
        }

        /// <summary>
        /// A matrix as a string.
        /// </summary>
        public override string ToString()
        {
            return this[0, 0] + "," + this[0, 1] + "," + this[0, 2] + "\n" +
                    this[1, 0] + "," + this[1, 1] + "," + this[1, 2] + "\n" +
                    this[2, 0] + "," + this[2, 1] + "," + this[2, 2];
        }

        /// <summary>
        /// The Inverse of the matrix copied into mInv.
        /// Returns false if the matrix has no inverse.
        /// A matrix multipled by its inverse is the idenity.
        /// Invert a 3x3 using cofactors.  This is about 8 times faster than
        /// the Numerical Recipes code which uses Gaussian elimination.
        /// </summary>
        public bool TryInverse(out Matrix3x3d mInv)
        {
            mInv.m00 = m11 * m22 - m12 * m21;
            mInv.m01 = m02 * m21 - m01 * m22;
            mInv.m02 = m01 * m12 - m02 * m11;
            mInv.m10 = m12 * m20 - m10 * m22;
            mInv.m11 = m00 * m22 - m02 * m20;
            mInv.m12 = m02 * m10 - m00 * m12;
            mInv.m20 = m10 * m21 - m11 * m20;
            mInv.m21 = m01 * m20 - m00 * m21;
            mInv.m22 = m00 * m11 - m01 * m10;

            double det = m00 * mInv.m00 + m01 * mInv.m10 + m02 * mInv.m20;

            if (DMath.IsZero(det))
            {
                mInv = Identity;
                return false;
            }

            double invDet = 1.0 / det;

            mInv.m00 *= invDet; mInv.m01 *= invDet; mInv.m02 *= invDet;
            mInv.m10 *= invDet; mInv.m11 *= invDet; mInv.m12 *= invDet;
            mInv.m20 *= invDet; mInv.m21 *= invDet; mInv.m22 *= invDet;

            return true;
        }

        /// <summary>
        /// Get the ith column as a vector.
        /// </summary>
        public Vector3d GetColumn(int iCol)
        {
			return new Vector3d(this[0, iCol], this[1, iCol], this[2, iCol]);
        }

        /// <summary>
        /// Set the ith column from avector.
        /// </summary>
        public void SetColumn(int iCol, Vector3d v)
        {
			this[0, iCol] = v.x;
			this[1, iCol] = v.y;
			this[2, iCol] = v.z;
        }

        /// <summary>
        /// Get the ith row as a vector.
        /// </summary>
        public Vector3d GetRow(int iRow)
        {
			return new Vector3d(this[iRow, 0], this[iRow, 1], this[iRow, 2]);
        }

        /// <summary>
        /// Set the ith row from avector.
        /// </summary>
        public void SetRow(int iRow, Vector3d v)
        {
			this[iRow, 0] = v.x;
			this[iRow, 1] = v.y;
			this[iRow, 2] = v.z;
        }

        /// <summary>
        /// Convert to a double precision 4 dimension matrix.
        /// </summary>
        public Matrix4x4d ToMatrix4x4d()
        {
            return new Matrix4x4d(m00, m01, m02, 0.0f,
                                  m10, m11, m12, 0.0f,
                                  m20, m21, m22, 0.0f,
                                  0.0f, 0.0f, 0.0f, 0.0f);
        }

        /// <summary>
        /// Create a translation out of a vector.
        /// </summary>
        static public Matrix3x3d Translate(Vector2d v)
        {
            return new Matrix3x3d(1, 0, v.x,
                                  0, 1, v.y,
                                  0, 0, 1);
        }

        /// <summary>
        /// Create a scale out of a vector.
        /// </summary>
        static public Matrix3x3d Scale(Vector2d v)
        {
            return new Matrix3x3d(v.x, 0, 0,
                                  0, v.y, 0,
                                  0, 0, 1);

        }

        /// <summary>
        /// Create a scale out of a vector.
        /// </summary>
        static public Matrix3x3d Scale(double s)
        {
            return new Matrix3x3d(s, 0, 0,
                                  0, s, 0,
                                  0, 0, 1);

        }

        /// <summary>
        /// Create a rotation out of a angle.
        /// </summary>
        static public Matrix3x3d RotateX(double angle)
        {
            double ca = Math.Cos(angle * Math.PI / 180.0);
            double sa = Math.Sin(angle * Math.PI / 180.0);

            return new Matrix3x3d(1, 0, 0,
                                  0, ca, -sa,
                                  0, sa, ca);
        }

        /// <summary>
        /// Create a rotation out of a angle.
        /// </summary>
        static public Matrix3x3d RotateY(double angle)
        {
            double ca = Math.Cos(angle * Math.PI / 180.0);
            double sa = Math.Sin(angle * Math.PI / 180.0);

            return new Matrix3x3d(ca, 0, sa,
                                  0, 1, 0,
                                  -sa, 0, ca);
        }

        /// <summary>
        /// Create a rotation out of a angle.
        /// </summary>
        static public Matrix3x3d RotateZ(double angle)
        {
            double ca = Math.Cos(angle * Math.PI / 180.0);
            double sa = Math.Sin(angle * Math.PI / 180.0);

            return new Matrix3x3d(ca, -sa, 0,
                                  sa, ca, 0,
                                  0, 0, 1);
        }

        /// <summary>
        /// Create a rotation out of a vector.
        /// </summary>
        static public Matrix3x3d Rotate(Vector3d euler)
        {
            return Quaternion3d.FromEuler(euler).ToMatrix3x3d();
        }

    }

}



























================================================
FILE: Assets/Common/LinearAlgebra/Matrix3x3d.cs.meta
================================================
fileFormatVersion: 2
guid: e1ff789641c35454ebfd3d438dcc6189
timeCreated: 1514536271
licenseType: Free
MonoImporter:
  externalObjects: {}
  serializedVersion: 2
  defaultReferences: []
  executionOrder: 0
  icon: {instanceID: 0}
  userData: 
  assetBundleName: 
  assetBundleVariant: 


================================================
FILE: Assets/Common/LinearAlgebra/Matrix3x3f.cs
================================================
using System;
using System.Collections;
using System.Runtime.InteropServices;

using Common.Core.Mathematics;

namespace Common.Core.LinearAlgebra
{
    /// <summary>
    /// A single precision 3 dimension matrix
    /// </summary>
    [StructLayout(LayoutKind.Sequential)]
    public struct Matrix3x3f
    {
        /// <summary>
        /// The matrix
        /// </summary>
        public float m00, m01, m02;
        public float m10, m11, m12;
        public float m20, m21, m22;

        /// <summary>
        /// The Matrix Idenity.
        /// </summary>
        static readonly public Matrix3x3f Identity = new Matrix3x3f(1, 0, 0, 0, 1, 0, 0, 0, 1);

        /// <summary>
        /// A matrix from the following varibles.
        /// </summary>
        public Matrix3x3f(float m00, float m01, float m02,
                          float m10, float m11, float m12,
                          float m20, float m21, float m22)
        {
			this.m00 = m00; this.m01 = m01; this.m02 = m02;
			this.m10 = m10; this.m11 = m11; this.m12 = m12;
			this.m20 = m20; this.m21 = m21; this.m22 = m22;

        }

        /// <summary>
        /// A matrix from the following varibles.
        /// </summary>
        public Matrix3x3f(float v)
        {
            m00 = v; m01 = v; m02 = v;
            m10 = v; m11 = v; m12 = v;
            m20 = v; m21 = v; m22 = v;
        }

        /// <summary>
        /// A matrix copied from a array of varibles.
        /// </summary>
        public Matrix3x3f(float[,] m)
        {
            m00 = m[0, 0]; m01 = m[0, 1]; m02 = m[0, 2];
            m10 = m[1, 0]; m11 = m[1, 1]; m12 = m[1, 2];
            m20 = m[2, 0]; m21 = m[2, 1]; m22 = m[2, 2];
        }

		/// <summary>
		/// A matrix copied from a array of varibles.
		/// </summary>
		public Matrix3x3f(float[] m)
		{
            m00 = m[0 + 0 * 3]; m01 = m[0 + 1 * 3]; m02 = m[0 + 2 * 3];
            m10 = m[1 + 0 * 3]; m11 = m[1 + 1 * 3]; m12 = m[1 + 2 * 3];
            m20 = m[2 + 0 * 3]; m21 = m[2 + 1 * 3]; m22 = m[2 + 2 * 3];
		}

        public float Trace
        {
            get
            {
                return m00 + m11 + m22;
            }
        }

        /// <summary>
        /// Access the varible at index i
        /// </summary>
        public float this[int i]
        {
            get
            {
                switch (i)
                {
                    case 0: return m00;
                    case 1: return m10;
                    case 2: return m20;
                    case 3: return m01;
                    case 4: return m11;
                    case 5: return m21;
                    case 6: return m02;
                    case 7: return m12;
                    case 8: return m22;
                    default: throw new IndexOutOfRangeException("Matrix3x3f index out of range: " + i);
                }
            }
            set
            {
                switch (i)
                {
                    case 0: m00 = value; break;
                    case 1: m10 = value; break;
                    case 2: m20 = value; break;
                    case 3: m01 = value; break;
                    case 4: m11 = value; break;
                    case 5: m21 = value; break;
                    case 6: m02 = value; break;
                    case 7: m12 = value; break;
                    case 8: m22 = value; break;
                    default: throw new IndexOutOfRangeException("Matrix3x3f index out of range: " + i);
                }
            }
        }

        /// <summary>
        /// Access the varible at index ij
        /// </summary>
        public float this[int i, int j]
        {
            get
            {
                int k = i + j * 3;
                switch (k)
                {
                    case 0: return m00;
                    case 1: return m10;
                    case 2: return m20;
                    case 3: return m01;
                    case 4: return m11;
                    case 5: return m21;
                    case 6: return m02;
                    case 7: return m12;
                    case 8: return m22;
                    default: throw new IndexOutOfRangeException("Matrix3x3f index out of range: " + k);
                }
            }
            set
            {
                int k = i + j * 3;
                switch (k)
                {
                    case 0: m00 = value; break;
                    case 1: m10 = value; break;
                    case 2: m20 = value; break;
                    case 3: m01 = value; break;
                    case 4: m11 = value; break;
                    case 5: m21 = value; break;
                    case 6: m02 = value; break;
                    case 7: m12 = value; break;
                    case 8: m22 = value; break;
                    default: throw new IndexOutOfRangeException("Matrix3x3f index out of range: " + k);
                }
            }
        }

        /// <summary>
        /// The transpose of the matrix. The rows and columns are flipped.
        /// </summary>
        public Matrix3x3f Transpose
        {
            get
            {
                Matrix3x3f transpose = new Matrix3x3f();

                transpose.m00 = m00;
                transpose.m01 = m10;
                transpose.m02 = m20;

                transpose.m10 = m01;
                transpose.m11 = m11;
                transpose.m12 = m21;

                transpose.m20 = m02;
                transpose.m21 = m12;
                transpose.m22 = m22;

                return transpose;
            }
        }

        /// <summary>
        /// The determinate of a matrix. 
        /// </summary>
        public float Determinant
        {
            get
            {
                float cofactor00 = m11 * m22 - m12 * m21;
                float cofactor10 = m12 * m20 - m10 * m22;
                float cofactor20 = m10 * m21 - m11 * m20;

                float det = m00 * cofactor00 + m01 * cofactor10 + m02 * cofactor20;

                return det;
            }
        }

        /// <summary>
        /// The inverse of the matrix.
        /// A matrix multipled by its inverse is the idenity.
        /// </summary>
        public Matrix3x3f Inverse
        {
            get
            {
                Matrix3x3f inverse = Identity;
                TryInverse(out inverse);
                return inverse;
            }
        }

        /// <summary>
        /// Add two matrices.
        /// </summary>
        public static Matrix3x3f operator +(Matrix3x3f m1, Matrix3x3f m2)
        {
            Matrix3x3f kSum = new Matrix3x3f();
            kSum.m00 = m1.m00 + m2.m00;
            kSum.m01 = m1.m01 + m2.m01;
            kSum.m02 = m1.m02 + m2.m02;

            kSum.m10 = m1.m10 + m2.m10;
            kSum.m11 = m1.m11 + m2.m11;
            kSum.m12 = m1.m12 + m2.m12;

            kSum.m20 = m1.m20 + m2.m20;
            kSum.m21 = m1.m21 + m2.m21;
            kSum.m22 = m1.m22 + m2.m22;

            return kSum;
        }

        /// <summary>
        /// Subtract two matrices.
        /// </summary>
        public static Matrix3x3f operator -(Matrix3x3f m1, Matrix3x3f m2)
        {
            Matrix3x3f kSum = new Matrix3x3f();
            kSum.m00 = m1.m00 - m2.m00;
            kSum.m01 = m1.m01 - m2.m01;
            kSum.m02 = m1.m02 - m2.m02;

            kSum.m10 = m1.m10 - m2.m10;
            kSum.m11 = m1.m11 - m2.m11;
            kSum.m12 = m1.m12 - m2.m12;

            kSum.m20 = m1.m20 - m2.m20;
            kSum.m21 = m1.m21 - m2.m21;
            kSum.m22 = m1.m22 - m2.m22;
            return kSum;
        }

        /// <summary>
        /// Multiply two matrices.
        /// </summary>
        public static Matrix3x3f operator *(Matrix3x3f m1, Matrix3x3f m2)
        {
            Matrix3x3f kProd = new Matrix3x3f();

            kProd.m00 = m1.m00 * m2.m00 + m1.m01 * m2.m10 + m1.m02 * m2.m20;
            kProd.m01 = m1.m00 * m2.m01 + m1.m01 * m2.m11 + m1.m02 * m2.m21;
            kProd.m02 = m1.m00 * m2.m02 + m1.m01 * m2.m12 + m1.m02 * m2.m22;

            kProd.m10 = m1.m10 * m2.m00 + m1.m11 * m2.m10 + m1.m12 * m2.m20;
            kProd.m11 = m1.m10 * m2.m01 + m1.m11 * m2.m11 + m1.m12 * m2.m21;
            kProd.m12 = m1.m10 * m2.m02 + m1.m11 * m2.m12 + m1.m12 * m2.m22;

            kProd.m20 = m1.m20 * m2.m00 + m1.m21 * m2.m10 + m1.m22 * m2.m20;
            kProd.m21 = m1.m20 * m2.m01 + m1.m21 * m2.m11 + m1.m22 * m2.m21;
            kProd.m22 = m1.m20 * m2.m02 + m1.m21 * m2.m12 + m1.m22 * m2.m22;

            return kProd;
        }

        /// <summary>
        /// Multiply  a vector by a matrix.
        /// </summary>
        public static Vector3f operator *(Matrix3x3f m, Vector3f v)
        {
            Vector3f kProd = new Vector3f();

			kProd.x = m.m00 * v.x + m.m01 * v.y + m.m02 * v.z;
			kProd.y = m.m10 * v.x + m.m11 * v.y + m.m12 * v.z;
			kProd.z = m.m20 * v.x + m.m21 * v.y + m.m22 * v.z;

            return kProd;
        }

        /// <summary>
        /// Multiply a matrix by a scalar.
        /// </summary>
        public static Matrix3x3f operator *(Matrix3x3f m1, float s)
        {
            Matrix3x3f kProd = new Matrix3x3f();
            kProd.m00 = m1.m00 * s;
            kProd.m01 = m1.m01 * s;
            kProd.m02 = m1.m02 * s;

            kProd.m10 = m1.m10 * s;
            kProd.m11 = m1.m11 * s;
            kProd.m12 = m1.m12 * s;

            kProd.m20 = m1.m20 * s;
            kProd.m21 = m1.m21 * s;
            kProd.m22 = m1.m22 * s;

            return kProd;
        }

        /// <summary>
        /// Multiply a matrix by a scalar.
        /// </summary>
        public static Matrix3x3f operator *(float s, Matrix3x3f m1)
        {
            Matrix3x3f kProd = new Matrix3x3f();
            kProd.m00 = m1.m00 * s;
            kProd.m01 = m1.m01 * s;
            kProd.m02 = m1.m02 * s;

            kProd.m10 = m1.m10 * s;
            kProd.m11 = m1.m11 * s;
            kProd.m12 = m1.m12 * s;

            kProd.m20 = m1.m20 * s;
            kProd.m21 = m1.m21 * s;
            kProd.m22 = m1.m22 * s;

            return kProd;
        }

        /// <summary>
        /// Are these matrices equal.
        /// </summary>
        public static bool operator ==(Matrix3x3f m1, Matrix3x3f m2)
        {

            if (m1.m00 != m2.m00) return false;
            if (m1.m01 != m2.m01) return false;
            if (m1.m02 != m2.m02) return false;

            if (m1.m10 != m2.m10) return false;
            if (m1.m11 != m2.m11) return false;
            if (m1.m12 != m2.m12) return false;

            if (m1.m20 != m2.m20) return false;
            if (m1.m21 != m2.m21) return false;
            if (m1.m22 != m2.m22) return false;

            return true;
        }

        /// <summary>
        /// Are these matrices not equal.
        /// </summary>
        public static bool operator !=(Matrix3x3f m1, Matrix3x3f m2)
        {
            if (m1.m00 != m2.m00) return true;
            if (m1.m01 != m2.m01) return true;
            if (m1.m02 != m2.m02) return true;

            if (m1.m10 != m2.m10) return true;
            if (m1.m11 != m2.m11) return true;
            if (m1.m12 != m2.m12) return true;

            if (m1.m20 != m2.m20) return true;
            if (m1.m21 != m2.m21) return true;
            if (m1.m22 != m2.m22) return true;

            return false;
        }

		/// <summary>
		/// Are these matrices equal.
		/// </summary>
		public override bool Equals (object obj)
		{
			if(!(obj is Matrix3x3f)) return false;
			
			Matrix3x3f mat = (Matrix3x3f)obj;
			
			return this == mat;
		}

        /// <summary>
        /// Are these matrices equal.
        /// </summary>
        public bool Equals(Matrix3x3f mat)
        {
            return this == mat;
        }

        /// <summary>
        /// Are these matrices equal.
        /// </summary>
        public bool EqualsWithError(Matrix3x3f m, float eps)
        {
            if (Math.Abs(m00 - m.m00) > eps) return false;
            if (Math.Abs(m10 - m.m10) > eps) return false;
            if (Math.Abs(m20 - m.m20) > eps) return false;

            if (Math.Abs(m01 - m.m01) > eps) return false;
            if (Math.Abs(m11 - m.m11) > eps) return false;
            if (Math.Abs(m21 - m.m21) > eps) return false;

            if (Math.Abs(m02 - m.m02) > eps) return false;
            if (Math.Abs(m12 - m.m12) > eps) return false;
            if (Math.Abs(m22 - m.m22) > eps) return false;

            return true;
        }
		
		/// <summary>
		/// Matrices hash code. 
		/// </summary>
		public override int GetHashCode()
		{
			int hash = 0;
			
			for(int i = 0; i < 9; i++)
				hash ^= this[i].GetHashCode();
			
			return hash;
		}

        /// <summary>
        /// A matrix as a string.
        /// </summary>
        public override string ToString()
        {
			return 	this[0, 0] + "," + this[0, 1] + "," + this[0, 2] + "\n" +
					this[1, 0] + "," + this[1, 1] + "," + this[1, 2] + "\n" +
					this[2, 0] + "," + this[2, 1] + "," + this[2, 2];
        }

        /// <summary>
        /// The Inverse of the matrix copied into mInv.
        /// Returns false if the matrix has no inverse.
        /// A matrix multipled by its inverse is the idenity.
        /// Invert a 3x3 using cofactors.  This is about 8 times faster than
        /// the Numerical Recipes code which uses Gaussian elimination.
        /// </summary>
        public bool TryInverse(out Matrix3x3f mInv)
        {
			mInv.m00 = m11 * m22 - m12 * m21;
			mInv.m01 = m02 * m21 - m01 * m22;
			mInv.m02 = m01 * m12 - m02 * m11;
			mInv.m10 = m12 * m20 - m10 * m22;
			mInv.m11 = m00 * m22 - m02 * m20;
			mInv.m12 = m02 * m10 - m00 * m12;
			mInv.m20 = m10 * m21 - m11 * m20;
			mInv.m21 = m01 * m20 - m00 * m21;
			mInv.m22 = m00 * m11 - m01 * m10;

			float det = m00 * mInv.m00 + m01 * mInv.m10 + m02 * mInv.m20;

            if (FMath.IsZero(det))
            {
                mInv = Identity;
                return false;
            }

            float invDet = 1.0f / det;

            mInv.m00 *= invDet; mInv.m01 *= invDet; mInv.m02 *= invDet;
            mInv.m10 *= invDet; mInv.m11 *= invDet; mInv.m12 *= invDet;
            mInv.m20 *= invDet; mInv.m21 *= invDet; mInv.m22 *= invDet;

            return true;
        }

        /// <summary>
        /// Get the ith column as a vector.
        /// </summary>
        public Vector3f GetColumn(int iCol)
        {
			return new Vector3f(this[0, iCol], this[1, iCol], this[2, iCol]);
        }

        /// <summary>
        /// Set the ith column from avector.
        /// </summary>
        public void SetColumn(int iCol, Vector3f v)
        {
			this[0, iCol] = v.x;
			this[1, iCol] = v.y;
			this[2, iCol] = v.z;
        }

        /// <summary>
        /// Get the ith row as a vector.
        /// </summary>
        public Vector3f GetRow(int iRow)
        {
			return new Vector3f(this[iRow, 0], this[iRow, 1], this[iRow, 2]);
        }

        /// <summary>
        /// Set the ith row from avector.
        /// </summary>
        public void SetRow(int iRow, Vector3f v)
        {
			this[iRow, 0] = v.x;
			this[iRow, 1] = v.y;
			this[iRow, 2] = v.z;
        }

        /// <summary>
        /// Convert to a single precision 4 dimension matrix.
        /// </summary>
        public Matrix4x4f ToMatrix4x4f()
        {
			return new Matrix4x4f(m00, m01, m02, 0.0f,
			                      m10, m11, m12, 0.0f,
			                      m20, m21, m22, 0.0f,
                                  0.0f, 0.0f, 0.0f, 0.0f);
        }

        /// <summary>
        /// Create a translation out of a vector.
        /// </summary>
        static public Matrix3x3f Translate(Vector2f v)
        {
            return new Matrix3x3f(1, 0, v.x,
                                  0, 1, v.y,
                                  0, 0, 1);
        }

        /// <summary>
        /// Create a scale out of a vector.
        /// </summary>
        static public Matrix3x3f Scale(Vector2f v)
        {
            return new Matrix3x3f(v.x, 0, 0,
                                  0, v.y, 0, 
                                  0, 0, 1);                      
        }

        /// <summary>
        /// Create a scale out of a vector.
        /// </summary>
        static public Matrix3x3f Scale(float s)
        {
            return new Matrix3x3f(s, 0, 0,
                                  0, s, 0,
                                  0, 0, 1);
        }

        /// <summary>
        /// Create a rotation out of a angle.
        /// </summary>
        static public Matrix3x3f RotateX(float angle)
        {
            float ca = (float)Math.Cos(angle * Math.PI / 180.0);
            float sa = (float)Math.Sin(angle * Math.PI / 180.0);

            return new Matrix3x3f(1, 0, 0,
                                  0, ca, -sa,
                                  0, sa, ca);
        }

        /// <summary>
        /// Create a rotation out of a angle.
        /// </summary>
        static public Matrix3x3f RotateY(float angle)
        {
            float ca = (float)Math.Cos(angle * Math.PI / 180.0);
            float sa = (float)Math.Sin(angle * Math.PI / 180.0);

            return new Matrix3x3f(ca, 0, sa,
                                  0, 1, 0,
                                  -sa, 0, ca);
        }

        /// <summary>
        /// Create a rotation out of a angle.
        /// </summary>
        static public Matrix3x3f RotateZ(float angle)
        {
            float ca = (float)Math.Cos(angle * Math.PI / 180.0);
            float sa = (float)Math.Sin(angle * Math.PI / 180.0);

            return new Matrix3x3f(ca, -sa, 0,
                                  sa, ca, 0,
                                  0, 0, 1);
        }

        /// <summary>
        /// Create a rotation out of a vector.
        /// </summary>
        static public Matrix3x3f Rotate(Vector3f euler)
        {
            return Quaternion3f.FromEuler(euler).ToMatrix3x3f();
        }

    }

}



























================================================
FILE: Assets/Common/LinearAlgebra/Matrix3x3f.cs.meta
================================================
fileFormatVersion: 2
guid: 0d592915ed7730b46b7e07319de6f32c
timeCreated: 1514536270
licenseType: Free
MonoImporter:
  externalObjects: {}
  serializedVersion: 2
  defaultReferences: []
  executionOrder: 0
  icon: {instanceID: 0}
  userData: 
  assetBundleName: 
  assetBundleVariant: 


================================================
FILE: Assets/Common/LinearAlgebra/Matrix4x4d.cs
================================================
using System;
using System.Collections;
using System.Runtime.InteropServices;

using Common.Core.Mathematics;

namespace Common.Core.LinearAlgebra
{
    /// <summary>
    /// A single precision 3 dimension matrix
    /// </summary>
    [StructLayout(LayoutKind.Sequential)]
    public struct Matrix4x4d
	{

        /// <summary>
        /// The matrix
        /// </summary>
        public double m00, m01, m02, m03;
        public double m10, m11, m12, m13;
        public double m20, m21, m22, m23;
        public double m30, m31, m32, m33;

        /// <summary>
        /// The Matrix Idenity.
        /// </summary>
        static readonly public Matrix4x4d Identity = new Matrix4x4d(1, 0, 0, 0,
                                                                    0, 1, 0, 0,
                                                                    0, 0, 1, 0,
                                                                    0, 0, 0, 1);

        /// <summary>
        /// A matrix from the following varibles.
        /// </summary>
        public Matrix4x4d(double m00, double m01, double m02, double m03,
                          double m10, double m11, double m12, double m13,
                          double m20, double m21, double m22, double m23,
                          double m30, double m31, double m32, double m33)
        {
			this.m00 = m00; this.m01 = m01; this.m02 = m02; this.m03 = m03;
			this.m10 = m10; this.m11 = m11; this.m12 = m12; this.m13 = m13;
			this.m20 = m20; this.m21 = m21; this.m22 = m22; this.m23 = m23;
			this.m30 = m30; this.m31 = m31; this.m32 = m32; this.m33 = m33;

        }

        /// <summary>
        /// A matrix from the following varibles.
        /// </summary>
        public Matrix4x4d(double v)
        {
			m00 = v; m01 = v; m02 = v; m03 = v;
			m10 = v; m11 = v; m12 = v; m13 = v;
			m20 = v; m21 = v; m22 = v; m23 = v;
			m30 = v; m31 = v; m32 = v; m33 = v;
        }

        /// <summary>
        /// A matrix copied from a array of varibles.
        /// </summary>
        public Matrix4x4d(double[,] m)
        {
            m00 = m[0,0]; m01 = m[0,1]; m02 = m[0,2]; m03 = m[0,3];
			m10 = m[1,0]; m11 = m[1,1]; m12 = m[1,2]; m13 = m[1,3];
			m20 = m[2,0]; m21 = m[2,1]; m22 = m[2,2]; m23 = m[2,3];
			m30 = m[3,0]; m31 = m[3,1]; m32 = m[3,2]; m33 = m[3,3];
        }

		/// <summary>
		/// A matrix copied from a array of varibles.
		/// </summary>
		public Matrix4x4d(double[] m)
		{
			m00 = m[0+0* 4]; m01 = m[0+1* 4]; m02 = m[0+2* 4]; m03 = m[0+3* 4];
			m10 = m[1+0* 4]; m11 = m[1+1* 4]; m12 = m[1+2* 4]; m13 = m[1+3* 4];
			m20 = m[2+0* 4]; m21 = m[2+1* 4]; m22 = m[2+2* 4]; m23 = m[2+3* 4];
			m30 = m[3+0* 4]; m31 = m[3+1* 4]; m32 = m[3+2* 4]; m33 = m[3+3* 4];
		}
        
        /// <summary>
        /// Access the varible at index i
        /// </summary>
        public double this[int i]
        {
            get
            {
                switch (i)
                {
                    case 0: return m00;
                    case 1: return m10;
                    case 2: return m20;
                    case 3: return m30;

                    case 4: return m01;
                    case 5: return m11;
                    case 6: return m21;
                    case 7: return m31;

                    case 8: return m02;
                    case 9: return m12;
                    case 10: return m22;
                    case 11: return m32;

                    case 12: return m03;
                    case 13: return m13;
                    case 14: return m23;
                    case 15: return m33;
                    default: throw new IndexOutOfRangeException("Matrix4x4d index out of range: " + i);
                }
            }
            set
            {
                switch (i)
                {
                    case 0: m00 = value; break;
                    case 1: m10 = value; break;
                    case 2: m20 = value; break;
                    case 3: m30 = value; break;

                    case 4: m01 = value; break;
                    case 5: m11 = value; break;
                    case 6: m21 = value; break;
                    case 7: m31 = value; break;

                    case 8: m02 = value; break;
                    case 9: m12 = value; break;
                    case 10: m22 = value; break;
                    case 11: m32 = value; break;

                    case 12: m03 = value; break;
                    case 13: m13 = value; break;
                    case 14: m23 = value; break;
                    case 15: m33 = value; break;
                    default: throw new IndexOutOfRangeException("Matrix4x4d index out of range: " + i);
                }
            }
        }

        /// <summary>
        /// Access the varible at index ij
        /// </summary>
        public double this[int i, int j]
        {
            get
            {
                int k = i + j * 4;
                switch (k)
                {
                    case 0: return m00;
                    case 1: return m10;
                    case 2: return m20;
                    case 3: return m30;

                    case 4: return m01;
                    case 5: return m11;
                    case 6: return m21;
                    case 7: return m31;

                    case 8: return m02;
                    case 9: return m12;
                    case 10: return m22;
                    case 11: return m32;

                    case 12: return m03;
                    case 13: return m13;
                    case 14: return m23;
                    case 15: return m33;
                    default: throw new IndexOutOfRangeException("Matrix4x4d index out of range: " + k);
                }
            }
            set
            {
                int k = i + j * 4;
                switch (k)
                {
                    case 0: m00 = value; break;
                    case 1: m10 = value; break;
                    case 2: m20 = value; break;
                    case 3: m30 = value; break;

                    case 4: m01 = value; break;
                    case 5: m11 = value; break;
                    case 6: m21 = value; break;
                    case 7: m31 = value; break;

                    case 8: m02 = value; break;
                    case 9: m12 = value; break;
                    case 10: m22 = value; break;
                    case 11: m32 = value; break;

                    case 12: m03 = value; break;
                    case 13: m13 = value; break;
                    case 14: m23 = value; break;
                    case 15: m33 = value; break;
                    default: throw new IndexOutOfRangeException("Matrix4x4d index out of range: " + k);
                }
            }
        }

        /// <summary>
        /// The transpose of the matrix. The rows and columns are flipped.
        /// </summary>
        public Matrix4x4d Transpose
        {
            get
            {
                Matrix4x4d transpose = new Matrix4x4d();
                transpose.m00 = m00;
                transpose.m01 = m10;
                transpose.m02 = m20;
                transpose.m03 = m30;

                transpose.m10 = m01;
                transpose.m11 = m11;
                transpose.m12 = m21;
                transpose.m13 = m31;

                transpose.m20 = m02;
                transpose.m21 = m12;
                transpose.m22 = m22;
                transpose.m23 = m32;

                transpose.m30 = m03;
                transpose.m31 = m13;
                transpose.m32 = m23;
                transpose.m33 = m33;

                return transpose;
            }
        }

        /// <summary>
        /// The determinate of a matrix. 
        /// </summary>
        public double Determinant
        {
            get
            {
                return (m00 * Minor(1, 2, 3, 1, 2, 3) -
                        m01 * Minor(1, 2, 3, 0, 2, 3) +
                        m02 * Minor(1, 2, 3, 0, 1, 3) -
                        m03 * Minor(1, 2, 3, 0, 1, 2));
            }
        }

        /// <summary>
        /// The adjoint of a matrix. 
        /// </summary>
        public Matrix4x4d Adjoint
        {
            get
            {
                return new Matrix4x4d(
                        Minor(1, 2, 3, 1, 2, 3),
                        -Minor(0, 2, 3, 1, 2, 3),
                        Minor(0, 1, 3, 1, 2, 3),
                        -Minor(0, 1, 2, 1, 2, 3),

                        -Minor(1, 2, 3, 0, 2, 3),
                        Minor(0, 2, 3, 0, 2, 3),
                        -Minor(0, 1, 3, 0, 2, 3),
                        Minor(0, 1, 2, 0, 2, 3),

                        Minor(1, 2, 3, 0, 1, 3),
                        -Minor(0, 2, 3, 0, 1, 3),
                        Minor(0, 1, 3, 0, 1, 3),
                        -Minor(0, 1, 2, 0, 1, 3),

                        -Minor(1, 2, 3, 0, 1, 2),
                        Minor(0, 2, 3, 0, 1, 2),
                        -Minor(0, 1, 3, 0, 1, 2),
                        Minor(0, 1, 2, 0, 1, 2));
            }
        }

        /// <summary>
        /// The inverse of the matrix.
        /// A matrix multipled by its inverse is the idenity.
        /// </summary>
        public Matrix4x4d Inverse
        {
            get
            {
                return Adjoint * DMath.SafeInv(Determinant);
            }
        }

        public double Trace
        {
            get
            {
                return m00 + m11 + m22 + m33;
            }
        }

        /// <summary>
        /// Add two matrices.
        /// </summary>
        public static Matrix4x4d operator +(Matrix4x4d m1, Matrix4x4d m2)
        {
            Matrix4x4d kSum = new Matrix4x4d();
            kSum.m00 = m1.m00 + m2.m00;
            kSum.m01 = m1.m01 + m2.m01;
            kSum.m02 = m1.m02 + m2.m02;
            kSum.m03 = m1.m03 + m2.m03;

            kSum.m10 = m1.m10 + m2.m10;
            kSum.m11 = m1.m11 + m2.m11;
            kSum.m12 = m1.m12 + m2.m12;
            kSum.m13 = m1.m13 + m2.m13;

            kSum.m20 = m1.m20 + m2.m20;
            kSum.m21 = m1.m21 + m2.m21;
            kSum.m22 = m1.m22 + m2.m22;
            kSum.m23 = m1.m23 + m2.m23;

            kSum.m30 = m1.m30 + m2.m30;
            kSum.m31 = m1.m31 + m2.m31;
            kSum.m32 = m1.m32 + m2.m32;
            kSum.m33 = m1.m33 + m2.m33;

            return kSum;
        }

        /// <summary>
        /// Subtract two matrices.
        /// </summary>
        public static Matrix4x4d operator -(Matrix4x4d m1, Matrix4x4d m2)
        {
            Matrix4x4d kSum = new Matrix4x4d();
            kSum.m00 = m1.m00 - m2.m00;
            kSum.m01 = m1.m01 - m2.m01;
            kSum.m02 = m1.m02 - m2.m02;
            kSum.m03 = m1.m03 - m2.m03;

            kSum.m10 = m1.m10 - m2.m10;
            kSum.m11 = m1.m11 - m2.m11;
            kSum.m12 = m1.m12 - m2.m12;
            kSum.m13 = m1.m13 - m2.m13;

            kSum.m20 = m1.m20 - m2.m20;
            kSum.m21 = m1.m21 - m2.m21;
            kSum.m22 = m1.m22 - m2.m22;
            kSum.m23 = m1.m23 - m2.m23;

            kSum.m30 = m1.m30 - m2.m30;
            kSum.m31 = m1.m31 - m2.m31;
            kSum.m32 = m1.m32 - m2.m32;
            kSum.m33 = m1.m33 - m2.m33;
            return kSum;
        }

        /// <summary>
        /// Multiply two matrices.
        /// </summary>
        public static Matrix4x4d operator *(Matrix4x4d m1, Matrix4x4d m2)
        {
            Matrix4x4d kProd = new Matrix4x4d();
  
            kProd.m00 = m1.m00 * m2.m00 + m1.m01 * m2.m10 + m1.m02 * m2.m20 + m1.m03 * m2.m30;
            kProd.m01 = m1.m00 * m2.m01 + m1.m01 * m2.m11 + m1.m02 * m2.m21 + m1.m03 * m2.m31;
            kProd.m02 = m1.m00 * m2.m02 + m1.m01 * m2.m12 + m1.m02 * m2.m22 + m1.m03 * m2.m32;
            kProd.m03 = m1.m00 * m2.m03 + m1.m01 * m2.m13 + m1.m02 * m2.m23 + m1.m03 * m2.m33;

            kProd.m10 = m1.m10 * m2.m00 + m1.m11 * m2.m10 + m1.m12 * m2.m20 + m1.m13 * m2.m30;
            kProd.m11 = m1.m10 * m2.m01 + m1.m11 * m2.m11 + m1.m12 * m2.m21 + m1.m13 * m2.m31;
            kProd.m12 = m1.m10 * m2.m02 + m1.m11 * m2.m12 + m1.m12 * m2.m22 + m1.m13 * m2.m32;
            kProd.m13 = m1.m10 * m2.m03 + m1.m11 * m2.m13 + m1.m12 * m2.m23 + m1.m13 * m2.m33;

            kProd.m20 = m1.m20 * m2.m00 + m1.m21 * m2.m10 + m1.m22 * m2.m20 + m1.m23 * m2.m30;
            kProd.m21 = m1.m20 * m2.m01 + m1.m21 * m2.m11 + m1.m22 * m2.m21 + m1.m23 * m2.m31;
            kProd.m22 = m1.m20 * m2.m02 + m1.m21 * m2.m12 + m1.m22 * m2.m22 + m1.m23 * m2.m32;
            kProd.m23 = m1.m20 * m2.m03 + m1.m21 * m2.m13 + m1.m22 * m2.m23 + m1.m23 * m2.m33;

            kProd.m30 = m1.m30 * m2.m00 + m1.m31 * m2.m10 + m1.m32 * m2.m20 + m1.m33 * m2.m30;
            kProd.m31 = m1.m30 * m2.m01 + m1.m31 * m2.m11 + m1.m32 * m2.m21 + m1.m33 * m2.m31;
            kProd.m32 = m1.m30 * m2.m02 + m1.m31 * m2.m12 + m1.m32 * m2.m22 + m1.m33 * m2.m32;
            kProd.m33 = m1.m30 * m2.m03 + m1.m31 * m2.m13 + m1.m32 * m2.m23 + m1.m33 * m2.m33;
            return kProd;
        }

        /// <summary>
        /// Multiply  a vector by a matrix.
        /// </summary>
        public static Vector3d operator *(Matrix4x4d m, Vector3d v)
        {
            Vector3d kProd = new Vector3d();

			double invW = DMath.SafeInv(m.m30 * v.x + m.m31 * v.y + m.m32 * v.z + m.m33);

			kProd.x = (m.m00 * v.x + m.m01 * v.y + m.m02 * v.z + m.m03) * invW;
			kProd.y = (m.m10 * v.x + m.m11 * v.y + m.m12 * v.z + m.m13) * invW;
			kProd.z = (m.m20 * v.x + m.m21 * v.y + m.m22 * v.z + m.m23) * invW;

            return kProd;
        }

        /// <summary>
        /// Multiply  a vector by a matrix.
        /// </summary>
        public static Vector4d operator *(Matrix4x4d m, Vector4d v)
        {
            Vector4d kProd = new Vector4d();

			kProd.x = m.m00 * v.x + m.m01 * v.y + m.m02 * v.z + m.m03 * v.w;
			kProd.y = m.m10 * v.x + m.m11 * v.y + m.m12 * v.z + m.m13 * v.w;
			kProd.z = m.m20 * v.x + m.m21 * v.y + m.m22 * v.z + m.m23 * v.w;
			kProd.w = m.m30 * v.x + m.m31 * v.y + m.m32 * v.z + m.m33 * v.w;

            return kProd;
        }

        /// <summary>
        /// Multiply a matrix by a scalar.
        /// </summary>
        public static Matrix4x4d operator *(Matrix4x4d m1, double s)
        {
            Matrix4x4d kProd = new Matrix4x4d();
            kProd.m00 = m1.m00 * s;
            kProd.m01 = m1.m01 * s;
            kProd.m02 = m1.m02 * s;
            kProd.m03 = m1.m03 * s;

            kProd.m10 = m1.m10 * s;
            kProd.m11 = m1.m11 * s;
            kProd.m12 = m1.m12 * s;
            kProd.m13 = m1.m13 * s;

            kProd.m20 = m1.m20 * s;
            kProd.m21 = m1.m21 * s;
            kProd.m22 = m1.m22 * s;
            kProd.m23 = m1.m23 * s;

            kProd.m30 = m1.m30 * s;
            kProd.m31 = m1.m31 * s;
            kProd.m32 = m1.m32 * s;
            kProd.m33 = m1.m33 * s;
            return kProd;
        }

        /// <summary>
        /// Multiply a matrix by a scalar.
        /// </summary>
        public static Matrix4x4d operator *(double s, Matrix4x4d m1)
        {
            Matrix4x4d kProd = new Matrix4x4d();
            kProd.m00 = m1.m00 * s;
            kProd.m01 = m1.m01 * s;
            kProd.m02 = m1.m02 * s;
            kProd.m03 = m1.m03 * s;

            kProd.m10 = m1.m10 * s;
            kProd.m11 = m1.m11 * s;
            kProd.m12 = m1.m12 * s;
            kProd.m13 = m1.m13 * s;

            kProd.m20 = m1.m20 * s;
            kProd.m21 = m1.m21 * s;
            kProd.m22 = m1.m22 * s;
            kProd.m23 = m1.m23 * s;

            kProd.m30 = m1.m30 * s;
            kProd.m31 = m1.m31 * s;
            kProd.m32 = m1.m32 * s;
            kProd.m33 = m1.m33 * s;
            return kProd;
        }

        /// <summary>
        /// Are these matrices equal.
        /// </summary>
        public static bool operator ==(Matrix4x4d m1, Matrix4x4d m2)
        {

          if (m1.m00 != m2.m00) return false;
          if (m1.m01 != m2.m01) return false;
          if (m1.m02 != m2.m02) return false;
          if (m1.m03 != m2.m03) return false;

          if (m1.m10 != m2.m10) return false;
          if (m1.m11 != m2.m11) return false;
          if (m1.m12 != m2.m12) return false;
          if (m1.m13 != m2.m13) return false;

          if (m1.m20 != m2.m20) return false;
          if (m1.m21 != m2.m21) return false;
          if (m1.m22 != m2.m22) return false;
          if (m1.m23 != m2.m23) return false;

          if (m1.m30 != m2.m30) return false;
          if (m1.m31 != m2.m31) return false;
          if (m1.m32 != m2.m32) return false;
          if (m1.m33 != m2.m33) return false;

          return true;
        }

        /// <summary>
        /// Are these matrices not equal.
        /// </summary>
        public static bool operator !=(Matrix4x4d m1, Matrix4x4d m2)
        {
          if (m1.m00 != m2.m00) return true;
          if (m1.m01 != m2.m01) return true;
          if (m1.m02 != m2.m02) return true;
          if (m1.m03 != m2.m03) return true;

          if (m1.m10 != m2.m10) return true;
          if (m1.m11 != m2.m11) return true;
          if (m1.m12 != m2.m12) return true;
          if (m1.m13 != m2.m13) return true;

          if (m1.m20 != m2.m20) return true;
          if (m1.m21 != m2.m21) return true;
          if (m1.m22 != m2.m22) return true;
          if (m1.m23 != m2.m23) return true;

          if (m1.m30 != m2.m30) return true;
          if (m1.m31 != m2.m31) return true;
          if (m1.m32 != m2.m32) return true;

            return false;
        }

		/// <summary>
		/// Are these matrices equal.
		/// </summary>
		public override bool Equals (object obj)
		{
			if(!(obj is Matrix4x4d)) return false;

			Matrix4x4d mat = (Matrix4x4d)obj;

			return this == mat;
		}

        /// <summary>
		/// Are these matrices equal.
		/// </summary>
        public bool Equals (Matrix4x4d mat)
		{
			return this == mat;
		}

        /// <summary>
        /// Are these matrices equal.
        /// </summary>
        public bool EqualsWithError(Matrix4x4d m, double eps)
        {
            if (Math.Abs(m00 - m.m00) > eps) return false;
            if (Math.Abs(m10 - m.m10) > eps) return false;
            if (Math.Abs(m20 - m.m20) > eps) return false;
            if (Math.Abs(m30 - m.m30) > eps) return false;

            if (Math.Abs(m01 - m.m01) > eps) return false;
            if (Math.Abs(m11 - m.m11) > eps) return false;
            if (Math.Abs(m21 - m.m21) > eps) return false;
            if (Math.Abs(m31 - m.m31) > eps) return false;

            if (Math.Abs(m02 - m.m02) > eps) return false;
            if (Math.Abs(m12 - m.m12) > eps) return false;
            if (Math.Abs(m22 - m.m22) > eps) return false;
            if (Math.Abs(m32 - m.m32) > eps) return false;

            if (Math.Abs(m03 - m.m03) > eps) return false;
            if (Math.Abs(m13 - m.m13) > eps) return false;
            if (Math.Abs(m23 - m.m23) > eps) return false;
            if (Math.Abs(m33 - m.m33) > eps) return false;

            return true;
        }

		/// <summary>
		/// Matrices hash code. 
		/// </summary>
		public override int GetHashCode()
		{
			int hash = 0;

			for(int i = 0; i < 16; i++)
				hash ^= this[i].GetHashCode();

			return hash;
		}

        /// <summary>
        /// A matrix as a string.
        /// </summary>
        public override string ToString()
        {
            return  this[0, 0] + "," + this[0, 1] + "," + this[0, 2] + "," + this[0, 3] + "\n" +
                    this[1, 0] + "," + this[1, 1] + "," + this[1, 2] + "," + this[1, 3] + "\n" +
                    this[2, 0] + "," + this[2, 1] + "," + this[2, 2] + "," + this[2, 3] + "\n" +
					this[3, 0] + "," + this[3, 1] + "," + this[3, 2] + "," + this[3, 3];
        }

        /// <summary>
        /// The minor of a matrix. 
        /// </summary>
        private double Minor(int r0, int r1, int r2, int c0, int c1, int c2)
        {
			return 	this[r0, c0] * (this[r1, c1] * this[r2, c2] - this[r2, c1] * this[r1, c2]) -
					this[r0, c1] * (this[r1, c0] * this[r2, c2] - this[r2, c0] * this[r1, c2]) +
					this[r0, c2] * (this[r1, c0] * this[r2, c1] - this[r2, c0] * this[r1, c1]);
        }

        /// <summary>
        /// The inverse of the matrix.
        /// A matrix multipled by its inverse is the idenity.
        /// </summary>
        public bool TryInverse(out Matrix4x4d mInv)
        {
            double det = Determinant;

            if (DMath.IsZero(det))
            {
                mInv = Identity;
                return false;
            }

            mInv = Adjoint * (1.0 / det);
            return true;
        }

        /// <summary>
        /// Get the ith column as a vector.
        /// </summary>
        public Vector4d GetColumn(int iCol)
		{
			return new Vector4d(this[0, iCol], this[1, iCol], this[2, iCol], this[3, iCol]);
		}
		
		/// <summary>
		/// Set the ith column from a vector.
		/// </summary>
		public void SetColumn(int iCol, Vector4d v)
		{
			this[0, iCol] = v.x;
			this[1, iCol] = v.y;
			this[2, iCol] = v.z;
			this[3, iCol] = v.w;
		}
		
		/// <summary>
		/// Flip the ith column.
		/// </summary>
		public void FlipColumn(int iCol)
		{
			this[0, iCol] *= -1.0;
			this[1, iCol] *= -1.0;
			this[2, iCol] *= -1.0;
			this[3, iCol] *= -1.0;
		}
		
		/// <summary>
		/// Get the ith row as a vector.
		/// </summary>
		public Vector4d GetRow(int iRow)
		{
			return new Vector4d(this[iRow, 0], this[iRow, 1], this[iRow, 2], this[iRow, 3]);
		}
		
		/// <summary>
		/// Set the ith row from a vector.
		/// </summary>
		public void SetRow(int iRow, Vector4d v)
		{
			this[iRow, 0] = v.x;
			this[iRow, 1] = v.y;
			this[iRow, 2] = v.z;
			this[iRow, 3] = v.w;
		}
		
		/// <summary>
		/// Flip the ith row.
		/// </summary>
		public void FlipRow(int iRow)
		{
			this[iRow, 0] *= -1.0f;
			this[iRow, 1] *= -1.0f;
			this[iRow, 2] *= -1.0f;
			this[iRow, 3] *= -1.0f;
		}

        /// <summary>
        /// Convert to a 3 dimension matrix.
        /// </summary>
        public Matrix3x3d ToMatrix3x3d()
        {
            Matrix3x3d mat = new Matrix3x3d();

            mat.m00 = m00; mat.m01 = m01; mat.m02 = m02;
            mat.m10 = m10; mat.m11 = m11; mat.m12 = m12;
            mat.m20 = m20; mat.m21 = m21; mat.m22 = m22;

            return mat;
        }

        /// <summary>
        /// Create a translation, rotation and scale.
        /// </summary>
        static public Matrix4x4d TranslateRotateScale(Vector3d t, Quaternion3d r, Vector3d s)
        {
            Matrix4x4d T = Translate(t);
            Matrix4x4d R = r.ToMatrix4x4d();
            Matrix4x4d S = Scale(s);

            return T * R * S;
        }

        /// <summary>
        /// Create a translation and rotation.
        /// </summary>
        static public Matrix4x4d TranslateRotate(Vector3d t, Quaternion3d r)
        {
            Matrix4x4d T = Translate(t);
            Matrix4x4d R = r.ToMatrix4x4d();

            return T * R;
        }

        /// <summary>
        /// Create a translation and scale.
        /// </summary>
        static public Matrix4x4d TranslateScale(Vector3d t, Vector3d s)
        {
            Matrix4x4d T = Translate(t);
            Matrix4x4d S = Scale(s);

            return T * S;
        }

        /// <summary>
        /// Create a rotation and scale.
        /// </summary>
        static public Matrix4x4d RotateScale(Quaternion3d r, Vector3d s)
        {
            Matrix4x4d R = r.ToMatrix4x4d();
            Matrix4x4d S = Scale(s);

            return R * S;
        }

        /// <summary>
        /// Create a translation out of a vector.
        /// </summary>
        static public Matrix4x4d Translate(Vector3d v)
        {
            return new Matrix4x4d(	1, 0, 0, v.x,
                                    0, 1, 0, v.y,
                                    0, 0, 1, v.z,
                                    0, 0, 0, 1);
        }

        /// <summary>
        /// Create a scale out of a vector.
        /// </summary>
        static public Matrix4x4d Scale(Vector3d v)
        {
            return new Matrix4x4d(	v.x, 0, 0, 0,
                                    0, v.y, 0, 0,
                                    0, 0, v.z, 0,
                                    0, 0, 0, 1);
        }

        /// <summary>
        /// Create a scale out of a vector.
        /// </summary>
        static public Matrix4x4d Scale(double s)
        {
            return new Matrix4x4d(s, 0, 0, 0,
                                  0, s, 0, 0,
                                  0, 0, s, 0,
                                  0, 0, 0, 1);
        }

        /// <summary>
        /// Create a rotation out of a angle.
        /// </summary>
        static public Matrix4x4d RotateX(double angle)
        {
			double ca = Math.Cos(angle * Math.PI / 180.0);
			double sa = Math.Sin(angle * Math.PI / 180.0);

            return new Matrix4x4d(	1, 0, 0, 0,
                                    0, ca, -sa, 0,
                                    0, sa, ca, 0,
                                    0, 0, 0, 1);
        }

        /// <summary>
        /// Create a rotation out of a angle.
        /// </summary>
        static public Matrix4x4d RotateY(double angle)
        {
			double ca = Math.Cos(angle * Math.PI / 180.0);
			double sa = Math.Sin(angle * Math.PI / 180.0);

            return new Matrix4x4d(	ca, 0, sa, 0,
                                    0, 1, 0, 0,
                                    -sa, 0, ca, 0,
                                    0, 0, 0, 1);
        }

        /// <summary>
        /// Create a rotation out of a angle.
        /// </summary>
        static public Matrix4x4d RotateZ(double angle)
        {
			double ca = Math.Cos(angle * Math.PI / 180.0);
			double sa = Math.Sin(angle * Math.PI / 180.0);

            return new Matrix4x4d(	ca, -sa, 0, 0,
                                    sa, ca, 0, 0,
                                    0, 0, 1, 0,
                                    0, 0, 0, 1);
        }

        /// <summary>
        /// Create a rotation out of a vector.
        /// </summary>
        static public Matrix4x4d Rotate(Vector3d euler)
        {
            return Quaternion3d.FromEuler(euler).ToMatrix4x4d();
        }

        /// <summary>
        /// Create a perspective matrix.
        /// </summary>
        static public Matrix4x4d Perspective(double fovy, double aspect, double zNear, double zFar)
        {
			double f = 1.0 / Math.Tan((fovy * Math.PI / 180.0) / 2.0);
            return new Matrix4x4d(	f / aspect, 0, 0, 0,
                                    0, f, 0, 0,
                                    0, 0, (zFar + zNear) / (zNear - zFar), (2.0f * zFar * zNear) / (zNear - zFar),
                                    0, 0, -1, 0);
        }

        /// <summary>
        /// Create a ortho matrix.
        /// </summary>
        static public Matrix4x4d Ortho(double xRight, double xLeft, double yTop, double yBottom, double zNear, double zFar)
        {
            double tx, ty, tz;
            tx = -(xRight + xLeft) / (xRight - xLeft);
            ty = -(yTop + yBottom) / (yTop - yBottom);
            tz = -(zFar + zNear) / (zFar - zNear);
            return new Matrix4x4d(	2.0 / (xRight - xLeft), 0, 0, tx,
                                    0, 2.0 / (yTop - yBottom), 0, ty,
                                    0, 0, -2.0 / (zFar - zNear), tz,
                                    0, 0, 0, 1);
        }

		/// <summary>
		/// Creates the matrix need to look at target from position.
		/// </summary>
		static public Matrix4x4d LookAt(Vector3d position, Vector3d target, Vector3d Up)
		{
			
			Vector3d zaxis = (position - target).Normalized;
			Vector3d xaxis = Up.Cross(zaxis).Normalized;
			Vector3d yaxis = zaxis.Cross(xaxis);
			
			return new Matrix4x4d(	xaxis.x, xaxis.y, xaxis.z, -Vector3d.Dot(xaxis, position),
			                      	yaxis.x, yaxis.y, yaxis.z, -Vector3d.Dot(yaxis, position),
			                      	zaxis.x, zaxis.y, zaxis.z, -Vector3d.Dot(zaxis, position),
			                      	0, 0, 0, 1);
		}


    }

}



























================================================
FILE: Assets/Common/LinearAlgebra/Matrix4x4d.cs.meta
================================================
fileFormatVersion: 2
guid: deeb67b15435ece419f1249c52ba4c99
timeCreated: 1514536271
licenseType: Free
MonoImporter:
  externalObjects: {}
  serializedVersion: 2
  defaultReferences: []
  executionOrder: 0
  icon: {instanceID: 0}
  userData: 
  assetBundleName: 
  assetBundleVariant: 


================================================
FILE: Assets/Common/LinearAlgebra/Matrix4x4f.cs
================================================
using System;
using System.Collections;
using System.Runtime.InteropServices;

using Common.Core.Mathematics;

namespace Common.Core.LinearAlgebra
{
    /// <summary>
    /// A single precision 3 dimension matrix
    /// </summary>
    [StructLayout(LayoutKind.Sequential)]
    public struct Matrix4x4f : IEquatable<Matrix4x4f>
	{

        /// <summary>
        /// The matrix
        /// </summary>
        public float m00, m01, m02, m03;
        public float m10, m11, m12, m13;
        public float m20, m21, m22, m23;
        public float m30, m31, m32, m33;

        /// <summary>
        /// The Matrix Idenity.
        /// </summary>
        static readonly public Matrix4x4f Identity = new Matrix4x4f(1, 0, 0, 0,
                                                                    0, 1, 0, 0,
                                                                    0, 0, 1, 0,
                                                                    0, 0, 0, 1);

        /// <summary>
        /// A matrix from the following varibles.
        /// </summary>
        public Matrix4x4f(float m00, float m01, float m02, float m03,
                          float m10, float m11, float m12, float m13,
                          float m20, float m21, float m22, float m23,
                          float m30, float m31, float m32, float m33)
        {
			this.m00 = m00; this.m01 = m01; this.m02 = m02; this.m03 = m03;
			this.m10 = m10; this.m11 = m11; this.m12 = m12; this.m13 = m13;
			this.m20 = m20; this.m21 = m21; this.m22 = m22; this.m23 = m23;
			this.m30 = m30; this.m31 = m31; this.m32 = m32; this.m33 = m33;

        }

        /// <summary>
        /// A matrix from the following varibles.
        /// </summary>
        public Matrix4x4f(float v)
        {
			m00 = v; m01 = v; m02 = v; m03 = v;
			m10 = v; m11 = v; m12 = v; m13 = v;
			m20 = v; m21 = v; m22 = v; m23 = v;
			m30 = v; m31 = v; m32 = v; m33 = v;
        }

        /// <summary>
        /// A matrix copied from a array of varibles.
        /// </summary>
        public Matrix4x4f(float[,] m)
        {
            m00 = m[0,0]; m01 = m[0,1]; m02 = m[0,2]; m03 = m[0,3];
			m10 = m[1,0]; m11 = m[1,1]; m12 = m[1,2]; m13 = m[1,3];
			m20 = m[2,0]; m21 = m[2,1]; m22 = m[2,2]; m23 = m[2,3];
			m30 = m[3,0]; m31 = m[3,1]; m32 = m[3,2]; m33 = m[3,3];
        }

		/// <summary>
		/// A matrix copied from a array of varibles.
		/// </summary>
		public Matrix4x4f(float[] m)
		{
			m00 = m[0+0* 4]; m01 = m[0+1* 4]; m02 = m[0+2* 4]; m03 = m[0+3* 4];
			m10 = m[1+0* 4]; m11 = m[1+1* 4]; m12 = m[1+2* 4]; m13 = m[1+3* 4];
			m20 = m[2+0* 4]; m21 = m[2+1* 4]; m22 = m[2+2* 4]; m23 = m[2+3* 4];
			m30 = m[3+0* 4]; m31 = m[3+1* 4]; m32 = m[3+2* 4]; m33 = m[3+3* 4];
		}

        /// <summary>
        /// Access the varible at index i
        /// </summary>
        public float this[int i]
        {
            get
            {
                switch (i)
                {
                    case 0: return m00;
                    case 1: return m10;
                    case 2: return m20;
                    case 3: return m30;

                    case 4: return m01;
                    case 5: return m11;
                    case 6: return m21;
                    case 7: return m31;

                    case 8: return m02;
                    case 9: return m12;
                    case 10: return m22;
                    case 11: return m32;

                    case 12: return m03;
                    case 13: return m13;
                    case 14: return m23;
                    case 15: return m33;
                    default: throw new IndexOutOfRangeException("Matrix4x4f index out of range: " + i);
                }
            }
            set
            {
                switch (i)
                {
                    case 0: m00 = value; break;
                    case 1: m10 = value; break;
                    case 2: m20 = value; break;
                    case 3: m30 = value; break;

                    case 4: m01 = value; break;
                    case 5: m11 = value; break;
                    case 6: m21 = value; break;
                    case 7: m31 = value; break;

                    case 8: m02 = value; break;
                    case 9: m12 = value; break;
                    case 10: m22 = value; break;
                    case 11: m32 = value; break;

                    case 12: m03 = value; break;
                    case 13: m13 = value; break;
                    case 14: m23 = value; break;
                    case 15: m33 = value; break;
                    default: throw new IndexOutOfRangeException("Matrix4x4f index out of range: " + i);
                }
            }
        }

        /// <summary>
        /// Access the varible at index ij
        /// </summary>
        public float this[int i, int j]
        {
            get
            {
                int k = i + j * 4;
                switch (k)
                {
                    case 0: return m00;
                    case 1: return m10;
                    case 2: return m20;
                    case 3: return m30;

                    case 4: return m01;
                    case 5: return m11;
                    case 6: return m21;
                    case 7: return m31;

                    case 8: return m02;
                    case 9: return m12;
                    case 10: return m22;
                    case 11: return m32;

                    case 12: return m03;
                    case 13: return m13;
                    case 14: return m23;
                    case 15: return m33;
                    default: throw new IndexOutOfRangeException("Matrix4x4f index out of range: " + k);
                }
            }
            set
            {
                int k = i + j * 4;
                switch (k)
                {
                    case 0: m00 = value; break;
                    case 1: m10 = value; break;
                    case 2: m20 = value; break;
                    case 3: m30 = value; break;

                    case 4: m01 = value; break;
                    case 5: m11 = value; break;
                    case 6: m21 = value; break;
                    case 7: m31 = value; break;

                    case 8: m02 = value; break;
                    case 9: m12 = value; break;
                    case 10: m22 = value; break;
                    case 11: m32 = value; break;

                    case 12: m03 = value; break;
                    case 13: m13 = value; break;
                    case 14: m23 = value; break;
                    case 15: m33 = value; break;
                    default: throw new IndexOutOfRangeException("Matrix4x4f index out of range: " + k);
                }
            }
        }

        /// <summary>
        /// The transpose of the matrix. The rows and columns are flipped.
        /// </summary>
        public Matrix4x4f Transpose
        {
            get
            {
                Matrix4x4f transpose = new Matrix4x4f();
                transpose.m00 = m00;
                transpose.m01 = m10;
                transpose.m02 = m20;
                transpose.m03 = m30;

                transpose.m10 = m01;
                transpose.m11 = m11;
                transpose.m12 = m21;
                transpose.m13 = m31;

                transpose.m20 = m02;
                transpose.m21 = m12;
                transpose.m22 = m22;
                transpose.m23 = m32;

                transpose.m30 = m03;
                transpose.m31 = m13;
                transpose.m32 = m23;
                transpose.m33 = m33;

                return transpose;
            }
        }

        /// <summary>
        /// The determinate of a matrix. 
        /// </summary>
        public float Determinant
        {
            get
            {
                return (m00 * Minor(1, 2, 3, 1, 2, 3) -
                        m01 * Minor(1, 2, 3, 0, 2, 3) +
                        m02 * Minor(1, 2, 3, 0, 1, 3) -
                        m03 * Minor(1, 2, 3, 0, 1, 2));
            }
        }

        /// <summary>
        /// The adjoint of a matrix. 
        /// </summary>
        public Matrix4x4f Adjoint
        {
            get
            {
                return new Matrix4x4f(
                        Minor(1, 2, 3, 1, 2, 3),
                        -Minor(0, 2, 3, 1, 2, 3),
                        Minor(0, 1, 3, 1, 2, 3),
                        -Minor(0, 1, 2, 1, 2, 3),

                        -Minor(1, 2, 3, 0, 2, 3),
                        Minor(0, 2, 3, 0, 2, 3),
                        -Minor(0, 1, 3, 0, 2, 3),
                        Minor(0, 1, 2, 0, 2, 3),

                        Minor(1, 2, 3, 0, 1, 3),
                        -Minor(0, 2, 3, 0, 1, 3),
                        Minor(0, 1, 3, 0, 1, 3),
                        -Minor(0, 1, 2, 0, 1, 3),

                        -Minor(1, 2, 3, 0, 1, 2),
                        Minor(0, 2, 3, 0, 1, 2),
                        -Minor(0, 1, 3, 0, 1, 2),
                        Minor(0, 1, 2, 0, 1, 2));
            }
        }

        /// <summary>
        /// The inverse of the matrix.
        /// A matrix multipled by its inverse is the idenity.
        /// </summary>
        public Matrix4x4f Inverse
        {
            get
            {
                return Adjoint * FMath.SafeInv(Determinant);
            }
        }

        public float Trace
        {
            get
            {
                return m00 + m11 + m22 + m33;
            }
        }

        /// <summary>
        /// Add two matrices.
        /// </summary>
        public static Matrix4x4f operator +(Matrix4x4f m1, Matrix4x4f m2)
        {
            Matrix4x4f kSum = new Matrix4x4f();
            kSum.m00 = m1.m00 + m2.m00;
            kSum.m01 = m1.m01 + m2.m01;
            kSum.m02 = m1.m02 + m2.m02;
            kSum.m03 = m1.m03 + m2.m03;

            kSum.m10 = m1.m10 + m2.m10;
            kSum.m11 = m1.m11 + m2.m11;
            kSum.m12 = m1.m12 + m2.m12;
            kSum.m13 = m1.m13 + m2.m13;

            kSum.m20 = m1.m20 + m2.m20;
            kSum.m21 = m1.m21 + m2.m21;
            kSum.m22 = m1.m22 + m2.m22;
            kSum.m23 = m1.m23 + m2.m23;

            kSum.m30 = m1.m30 + m2.m30;
            kSum.m31 = m1.m31 + m2.m31;
            kSum.m32 = m1.m32 + m2.m32;
            kSum.m33 = m1.m33 + m2.m33;

            return kSum;
        }

        /// <summary>
        /// Subtract two matrices.
        /// </summary>
        public static Matrix4x4f operator -(Matrix4x4f m1, Matrix4x4f m2)
        {
            Matrix4x4f kSum = new Matrix4x4f();
            kSum.m00 = m1.m00 - m2.m00;
            kSum.m01 = m1.m01 - m2.m01;
            kSum.m02 = m1.m02 - m2.m02;
            kSum.m03 = m1.m03 - m2.m03;

            kSum.m10 = m1.m10 - m2.m10;
            kSum.m11 = m1.m11 - m2.m11;
            kSum.m12 = m1.m12 - m2.m12;
            kSum.m13 = m1.m13 - m2.m13;

            kSum.m20 = m1.m20 - m2.m20;
            kSum.m21 = m1.m21 - m2.m21;
            kSum.m22 = m1.m22 - m2.m22;
            kSum.m23 = m1.m23 - m2.m23;

            kSum.m30 = m1.m30 - m2.m30;
            kSum.m31 = m1.m31 - m2.m31;
            kSum.m32 = m1.m32 - m2.m32;
            kSum.m33 = m1.m33 - m2.m33;
            return kSum;
        }

        /// <summary>
        /// Multiply two matrices.
        /// </summary>
        public static Matrix4x4f operator *(Matrix4x4f m1, Matrix4x4f m2)
        {
            Matrix4x4f kProd = new Matrix4x4f();
   
            kProd.m00 = m1.m00 * m2.m00 + m1.m01 * m2.m10 + m1.m02 * m2.m20 + m1.m03 * m2.m30;
            kProd.m01 = m1.m00 * m2.m01 + m1.m01 * m2.m11 + m1.m02 * m2.m21 + m1.m03 * m2.m31;
            kProd.m02 = m1.m00 * m2.m02 + m1.m01 * m2.m12 + m1.m02 * m2.m22 + m1.m03 * m2.m32;
            kProd.m03 = m1.m00 * m2.m03 + m1.m01 * m2.m13 + m1.m02 * m2.m23 + m1.m03 * m2.m33;

            kProd.m10 = m1.m10 * m2.m00 + m1.m11 * m2.m10 + m1.m12 * m2.m20 + m1.m13 * m2.m30;
            kProd.m11 = m1.m10 * m2.m01 + m1.m11 * m2.m11 + m1.m12 * m2.m21 + m1.m13 * m2.m31;
            kProd.m12 = m1.m10 * m2.m02 + m1.m11 * m2.m12 + m1.m12 * m2.m22 + m1.m13 * m2.m32;
            kProd.m13 = m1.m10 * m2.m03 + m1.m11 * m2.m13 + m1.m12 * m2.m23 + m1.m13 * m2.m33;

            kProd.m20 = m1.m20 * m2.m00 + m1.m21 * m2.m10 + m1.m22 * m2.m20 + m1.m23 * m2.m30;
            kProd.m21 = m1.m20 * m2.m01 + m1.m21 * m2.m11 + m1.m22 * m2.m21 + m1.m23 * m2.m31;
            kProd.m22 = m1.m20 * m2.m02 + m1.m21 * m2.m12 + m1.m22 * m2.m22 + m1.m23 * m2.m32;
            kProd.m23 = m1.m20 * m2.m03 + m1.m21 * m2.m13 + m1.m22 * m2.m23 + m1.m23 * m2.m33;

            kProd.m30 = m1.m30 * m2.m00 + m1.m31 * m2.m10 + m1.m32 * m2.m20 + m1.m33 * m2.m30;
            kProd.m31 = m1.m30 * m2.m01 + m1.m31 * m2.m11 + m1.m32 * m2.m21 + m1.m33 * m2.m31;
            kProd.m32 = m1.m30 * m2.m02 + m1.m31 * m2.m12 + m1.m32 * m2.m22 + m1.m33 * m2.m32;
            kProd.m33 = m1.m30 * m2.m03 + m1.m31 * m2.m13 + m1.m32 * m2.m23 + m1.m33 * m2.m33;
            return kProd;
        }

        /// <summary>
        /// Multiply  a vector by a matrix.
        /// </summary>
        public static Vector3f operator *(Matrix4x4f m, Vector3f v)
        {
            Vector3f kProd = new Vector3f();

			float invW = FMath.SafeInv(m.m30 * v.x + m.m31 * v.y + m.m32 * v.z + m.m33);

			kProd.x = (m.m00 * v.x + m.m01 * v.y + m.m02 * v.z + m.m03) * invW;
			kProd.y = (m.m10 * v.x + m.m11 * v.y + m.m12 * v.z + m.m13) * invW;
			kProd.z = (m.m20 * v.x + m.m21 * v.y + m.m22 * v.z + m.m23) * invW;

            return kProd;
        }

        /// <summary>
        /// Multiply  a vector by a matrix.
        /// </summary>
        public static Vector4f operator *(Matrix4x4f m, Vector4f v)
        {
            Vector4f kProd = new Vector4f();

			kProd.x = m.m00 * v.x + m.m01 * v.y + m.m02 * v.z + m.m03 * v.w;
			kProd.y = m.m10 * v.x + m.m11 * v.y + m.m12 * v.z + m.m13 * v.w;
			kProd.z = m.m20 * v.x + m.m21 * v.y + m.m22 * v.z + m.m23 * v.w;
			kProd.w = m.m30 * v.x + m.m31 * v.y + m.m32 * v.z + m.m33 * v.w;

            return kProd;
        }

        /// <summary>
        /// Multiply a matrix by a scalar.
        /// </summary>
        public static Matrix4x4f operator *(Matrix4x4f m1, float s)
        {
            Matrix4x4f kProd = new Matrix4x4f();
            kProd.m00 = m1.m00 * s;
            kProd.m01 = m1.m01 * s;
            kProd.m02 = m1.m02 * s;
            kProd.m03 = m1.m03 * s;

            kProd.m10 = m1.m10 * s;
            kProd.m11 = m1.m11 * s;
            kProd.m12 = m1.m12 * s;
            kProd.m13 = m1.m13 * s;

            kProd.m20 = m1.m20 * s;
            kProd.m21 = m1.m21 * s;
            kProd.m22 = m1.m22 * s;
            kProd.m23 = m1.m23 * s;

            kProd.m30 = m1.m30 * s;
            kProd.m31 = m1.m31 * s;
            kProd.m32 = m1.m32 * s;
            kProd.m33 = m1.m33 * s;
            return kProd;
        }

        /// <summary>
        /// Multiply a matrix by a scalar.
        /// </summary>
        public static Matrix4x4f operator *(float s, Matrix4x4f m1)
        {
            Matrix4x4f kProd = new Matrix4x4f();
            kProd.m00 = m1.m00 * s;
            kProd.m01 = m1.m01 * s;
            kProd.m02 = m1.m02 * s;
            kProd.m03 = m1.m03 * s;

            kProd.m10 = m1.m10 * s;
            kProd.m11 = m1.m11 * s;
            kProd.m12 = m1.m12 * s;
            kProd.m13 = m1.m13 * s;

            kProd.m20 = m1.m20 * s;
            kProd.m21 = m1.m21 * s;
            kProd.m22 = m1.m22 * s;
            kProd.m23 = m1.m23 * s;

            kProd.m30 = m1.m30 * s;
            kProd.m31 = m1.m31 * s;
            kProd.m32 = m1.m32 * s;
            kProd.m33 = m1.m33 * s;
            return kProd;
        }

        /// <summary>
        /// Are these matrices equal.
        /// </summary>
        public static bool operator ==(Matrix4x4f m1, Matrix4x4f m2)
        {

          if (m1.m00 != m2.m00) return false;
          if (m1.m01 != m2.m01) return false;
          if (m1.m02 != m2.m02) return false;
          if (m1.m03 != m2.m03) return false;

          if (m1.m10 != m2.m10) return false;
          if (m1.m11 != m2.m11) return false;
          if (m1.m12 != m2.m12) return false;
          if (m1.m13 != m2.m13) return false;

          if (m1.m20 != m2.m20) return false;
          if (m1.m21 != m2.m21) return false;
          if (m1.m22 != m2.m22) return false;
          if (m1.m23 != m2.m23) return false;

          if (m1.m30 != m2.m30) return false;
          if (m1.m31 != m2.m31) return false;
          if (m1.m32 != m2.m32) return false;
          if (m1.m33 != m2.m33) return false;

          return true;
        }

        /// <summary>
        /// Are these matrices not equal.
        /// </summary>
        public static bool operator !=(Matrix4x4f m1, Matrix4x4f m2)
        {
          if (m1.m00 != m2.m00) return true;
          if (m1.m01 != m2.m01) return true;
          if (m1.m02 != m2.m02) return true;
          if (m1.m03 != m2.m03) return true;

          if (m1.m10 != m2.m10) return true;
          if (m1.m11 != m2.m11) return true;
          if (m1.m12 != m2.m12) return true;
          if (m1.m13 != m2.m13) return true;

          if (m1.m20 != m2.m20) return true;
          if (m1.m21 != m2.m21) return true;
          if (m1.m22 != m2.m22) return true;
          if (m1.m23 != m2.m23) return true;

          if (m1.m30 != m2.m30) return true;
          if (m1.m31 != m2.m31) return true;
          if (m1.m32 != m2.m32) return true;

            return false;
        }

		/// <summary>
		/// Are these matrices equal.
		/// </summary>
		public override bool Equals (object obj)
		{
			if(!(obj is Matrix4x4f)) return false;

			Matrix4x4f mat = (Matrix4x4f)obj;

			return this == mat;
		}

        /// <summary>
		/// Are these matrices equal.
		/// </summary>
        public bool Equals (Matrix4x4f mat)
		{
			return this == mat;
		}

        /// <summary>
        /// Are these matrices equal.
        /// </summary>
        public bool EqualsWithError(Matrix4x4f m, float eps)
        {
            if (Math.Abs(m00 - m.m00) > eps) return false;
            if (Math.Abs(m10 - m.m10) > eps) return false;
            if (Math.Abs(m20 - m.m20) > eps) return false;
            if (Math.Abs(m30 - m.m30) > eps) return false;

            if (Math.Abs(m01 - m.m01) > eps) return false;
            if (Math.Abs(m11 - m.m11) > eps) return false;
            if (Math.Abs(m21 - m.m21) > eps) return false;
            if (Math.Abs(m31 - m.m31) > eps) return false;

            if (Math.Abs(m02 - m.m02) > eps) return false;
            if (Math.Abs(m12 - m.m12) > eps) return false;
            if (Math.Abs(m22 - m.m22) > eps) return false;
            if (Math.Abs(m32 - m.m32) > eps) return false;

            if (Math.Abs(m03 - m.m03) > eps) return false;
            if (Math.Abs(m13 - m.m13) > eps) return false;
            if (Math.Abs(m23 - m.m23) > eps) return false;
            if (Math.Abs(m33 - m.m33) > eps) return false;

            return true;
        }

		/// <summary>
		/// Matrices hash code. 
		/// </summary>
		public override int GetHashCode()
		{
			int hash = 0;

			for(int i = 0; i < 16; i++)
				hash ^= this[i].GetHashCode();

			return hash;
		}

        /// <summary>
        /// A matrix as a string.
        /// </summary>
        public override string ToString()
        {
            return  this[0, 0] + "," + this[0, 1] + "," + this[0, 2] + "," + this[0, 3] + "\n" +
                    this[1, 0] + "," + this[1, 1] + "," + this[1, 2] + "," + this[1, 3] + "\n" +
                    this[2, 0] + "," + this[2, 1] + "," + this[2, 2] + "," + this[2, 3] + "\n" +
					this[3, 0] + "," + this[3, 1] + "," + this[3, 2] + "," + this[3, 3];
        }

        /// <summary>
        /// The minor of a matrix. 
        /// </summary>
        private float Minor(int r0, int r1, int r2, int c0, int c1, int c2)
        {
			return 	this[r0, c0] * (this[r1, c1] * this[r2, c2] - this[r2, c1] * this[r1, c2]) -
					this[r0, c1] * (this[r1, c0] * this[r2, c2] - this[r2, c0] * this[r1, c2]) +
					this[r0, c2] * (this[r1, c0] * this[r2, c1] - this[r2, c0] * this[r1, c1]);
        }

        /// <summary>
        /// The inverse of the matrix.
        /// A matrix multipled by its inverse is the idenity.
        /// </summary>
        public bool TryInverse(out Matrix4x4f mInv)
        {

            float det = Determinant;

            if (FMath.IsZero(det))
            {
                mInv = Identity;
                return false;
            }

            mInv = Adjoint * (1.0f / det);
            return true;
        }

        /// <summary>
        /// Get the ith column as a vector.
        /// </summary>
        public Vector4f GetColumn(int iCol)
        {
			return new Vector4f(this[0, iCol], this[1, iCol], this[2, iCol], this[3, iCol]);
        }

        /// <summary>
        /// Set the ith column from a vector.
        /// </summary>
        public void SetColumn(int iCol, Vector4f v)
        {
			this[0, iCol] = v.x;
			this[1, iCol] = v.y;
			this[2, iCol] = v.z;
			this[3, iCol] = v.w;
        }

		/// <summary>
		/// Flip the ith column.
		/// </summary>
		public void FlipColumn(int iCol)
		{
			this[0, iCol] *= -1.0f;
			this[1, iCol] *= -1.0f;
			this[2, iCol] *= -1.0f;
			this[3, iCol] *= -1.0f;
		}

        /// <summary>
        /// Get the ith row as a vector.
        /// </summary>
        public Vector4f GetRow(int iRow)
        {
			return new Vector4f(this[iRow, 0], this[iRow, 1], this[iRow, 2], this[iRow, 3]);
        }

        /// <summary>
        /// Set the ith row from a vector.
        /// </summary>
        public void SetRow(int iRow, Vector4f v)
        {
			this[iRow, 0] = v.x;
			this[iRow, 1] = v.y;
			this[iRow, 2] = v.z;
			this[iRow, 3] = v.w;
        }

		/// <summary>
		/// Flip the ith row.
		/// </summary>
		public void FlipRow(int iRow)
		{
			this[iRow, 0] *= -1.0f;
			this[iRow, 1] *= -1.0f;
			this[iRow, 2] *= -1.0f;
			this[iRow, 3] *= -1.0f;
		}

        /// <summary>
        /// Convert to a 3 dimension matrix.
        /// </summary>
        public Matrix3x3f ToMatrix3x3f()
        {
            Matrix3x3f mat = new Matrix3x3f();

			mat.m00 = m00; mat.m01 = m01; mat.m02 = m02;
			mat.m10 = m10; mat.m11 = m11; mat.m12 = m12;
			mat.m20 = m20; mat.m21 = m21; mat.m22 = m22;

            return mat;
        }

        /// <summary>
        /// Create a translation, rotation and scale.
        /// </summary>
        static public Matrix4x4f TranslateRotateScale(Vector3f t, Quaternion3f r, Vector3f s)
        {
            Matrix4x4f T = Translate(t);
            Matrix4x4f R = r.ToMatrix4x4f();
            Matrix4x4f S = Scale(s);

            return T * R * S;
        }

        /// <summary>
        /// Create a translation and rotation.
        /// </summary>
        static public Matrix4x4f TranslateRotate(Vector3f t, Quaternion3f r)
        {
            Matrix4x4f T = Translate(t);
            Matrix4x4f R = r.ToMatrix4x4f();

            return T * R;
        }

        /// <summary>
        /// Create a translation and scale.
        /// </summary>
        static public Matrix4x4f TranslateScale(Vector3f t, Vector3f s)
        {
            Matrix4x4f T = Translate(t);
            Matrix4x4f S = Scale(s);

            return T * S;
        }

        /// <summary>
        /// Create a rotation and scale.
        /// </summary>
        static public Matrix4x4f RotateScale(Quaternion3f r, Vector3f s)
        {
            Matrix4x4f R = r.ToMatrix4x4f();
            Matrix4x4f S = Scale(s);

            return R * S;
        }

        /// <summary>
        /// Create a translation out of a vector.
        /// </summary>
        static public Matrix4x4f Translate(Vector3f v)
        {
            return new Matrix4x4f(	1, 0, 0, v.x,
                                    0, 1, 0, v.y,
                                    0, 0, 1, v.z,
                                    0, 0, 0, 1);
        }

        /// <summary>
        /// Create a scale out of a vector.
        /// </summary>
        static public Matrix4x4f Scale(Vector3f v)
        {
            return new Matrix4x4f(	v.x, 0, 0, 0,
                                    0, v.y, 0, 0,
                                    0, 0, v.z, 0,
                                    0, 0, 0, 1);
        }

        /// <summary>
        /// Create a scale out of a vector.
        /// </summary>
        static public Matrix4x4f Scale(float s)
        {
            return new Matrix4x4f(s, 0, 0, 0,
                                  0, s, 0, 0,
                                  0, 0, s, 0,
                                  0, 0, 0, 1);
        }

        /// <summary>
        /// Create a rotation out of a angle.
        /// </summary>
        static public Matrix4x4f RotateX(float angle)
        {
			float ca = (float)Math.Cos(angle * Math.PI / 180.0);
			float sa = (float)Math.Sin(angle * Math.PI / 180.0);

            return new Matrix4x4f(	1, 0, 0, 0,
                                    0, ca, -sa, 0,
                                    0, sa, ca, 0,
                                    0, 0, 0, 1);
        }

        /// <summary>
        /// Create a rotation out of a angle.
        /// </summary>
        static public Matrix4x4f RotateY(float angle)
        {
			float ca = (float)Math.Cos(angle * Math.PI / 180.0);
			float sa = (float)Math.Sin(angle * Math.PI / 180.0);

            return new Matrix4x4f(	ca, 0, sa, 0,
                                    0, 1, 0, 0,
                                    -sa, 0, ca, 0,
                                    0, 0, 0, 1);
        }

        /// <summary>
        /// Create a rotation out of a angle.
        /// </summary>
        static public Matrix4x4f RotateZ(float angle)
        {
			float ca = (float)Math.Cos(angle * Math.PI / 180.0);
			float sa = (float)Math.Sin(angle * Math.PI / 180.0);

            return new Matrix4x4f(	ca, -sa, 0, 0,
                                    sa, ca, 0, 0,
                                    0, 0, 1, 0,
                                    0, 0, 0, 1);
        }

        /// <summary>
        /// Create a rotation out of a vector.
        /// </summary>
        static public Matrix4x4f Rotate(Vector3f euler)
        {
            return Quaternion3f.FromEuler(euler).ToMatrix4x4f();
        }

        /// <summary>
        /// Create a perspective matrix.
        /// </summary>
        static public Matrix4x4f Perspective(float fovy, float aspect, float zNear, float zFar)
        {
			float f = 1.0f / (float)Math.Tan((fovy * Math.PI / 180.0) / 2.0);
            return new Matrix4x4f(	f / aspect, 0, 0, 0,
                                    0, f, 0, 0,
                                    0, 0, (zFar + zNear) / (zNear - zFar), (2.0f * zFar * zNear) / (zNear - zFar),
                                    0, 0, -1, 0);
        }

        /// <summary>
        /// Create a ortho matrix.
        /// </summary>
        static public Matrix4x4f Ortho(float xRight, float xLeft, float yTop, float yBottom, float zNear, float zFar)
        {
            float tx, ty, tz;
            tx = -(xRight + xLeft) / (xRight - xLeft);
            ty = -(yTop + yBottom) / (yTop - yBottom);
            tz = -(zFar + zNear) / (zFar - zNear);
            return new Matrix4x4f(	2.0f / (xRight - xLeft), 0, 0, tx,
                                    0, 2.0f / (yTop - yBottom), 0, ty,
                                    0, 0, -2.0f / (zFar - zNear), tz,
                                    0, 0, 0, 1);
        }

		/// <summary>
		/// Creates the matrix need to look at target from position.
		/// </summary>
		static public Matrix4x4f LookAt(Vector3f position, Vector3f target, Vector3f Up)
		{
			
			Vector3f zaxis = (position - target).Normalized;
			Vector3f xaxis = Up.Cross(zaxis).Normalized;
			Vector3f yaxis = zaxis.Cross(xaxis);
			
			return new Matrix4x4f(	xaxis.x, xaxis.y, xaxis.z, -Vector3f.Dot(xaxis, position),
			                      	yaxis.x, yaxis.y, yaxis.z, -Vector3f.Dot(yaxis, position),
			                      	zaxis.x, zaxis.y, zaxis.z, -Vector3f.Dot(zaxis, position),
			                      	0, 0, 0, 1);
		}


    }

}



























================================================
FILE: Assets/Common/LinearAlgebra/Matrix4x4f.cs.meta
================================================
fileFormatVersion: 2
guid: b23ff530d822b7145adbcab5a4583011
timeCreated: 1514536270
licenseType: Free
MonoImporter:
  externalObjects: {}
  serializedVersion: 2
  defaultReferences: []
  executionOrder: 0
  icon: {instanceID: 0}
  userData: 
  assetBundleName: 
  assetBundleVariant: 


================================================
FILE: Assets/Common/LinearAlgebra/MatrixMxN.cs
================================================
using System;
using System.Collections.Generic;

using Common.Core.Mathematics;

namespace Common.Core.LinearAlgebra
{
    public static class MatrixMxN
    {

        public static double[] MultiplyVector(double[,] matrix, double[] vector)
        {
            int M = matrix.GetLength(0);
            int N = matrix.GetLength(1);

            if (vector.Length != matrix.GetLength(1))
                throw new ArgumentException("Matrix must have same number of columns as vectors length.");

            double[] multiplied = new double[M];

            for (int i = 0; i < M; i++)
            {
                double sum = 0.0;
                for (int j = 0; j < N; j++)
                {
                    sum += vector[j] * matrix[i, j];
                }

                multiplied[i] = sum;
            }

            return multiplied;
        }

        public static double[] MultiplyMatrix(double[] matrix1, double[,] matrix2)
        {
            int M = matrix1.Length;
            int N = matrix2.GetLength(1);

            if (matrix1.Length != matrix2.GetLength(0))
                throw new ArgumentException("Matrix2 must have same number of rows as matrix1 has columns.");

            double[] multiplied = new double[N];

            for (int j = 0; j < N; j++)
            {
                double sum = 0.0;
                for (int i = 0; i < M; i++)
                {
                    sum += matrix1[i] * matrix2[i, j];
                }

                multiplied[j] = sum;
            }

            return multiplied;
        }

        public static double[,] MultiplyMatrix(double[,] matrix1, double[,] matrix2)
        {
            int M = matrix1.GetLength(0);
            int N = matrix2.GetLength(1);

            if (matrix1.GetLength(1) != matrix2.GetLength(0))
                throw new ArgumentException("Matrix2 must have same number of rows as matrix1 has columns.");

            double[,] multiplied = new double[M, N];

            for (int i = 0; i < M; i++)
            {
                for (int j = 0; j < N; j++)
                {
                    double sum = 0.0;
                    for (int k = 0; k < matrix1.GetLength(1); k++)
                    {
                        sum += matrix1[i, k] * matrix2[k, j];
                    }

                    multiplied[i, j] = sum;
                }
            }

            return multiplied;
        }

        public static double[,] MultiplyScalar(double[,] matrix, double v)
        {
            int M = matrix.GetLength(0);
            int N = matrix.GetLength(1);

            double[,] multiplied = new double[M, N];

            for (int i = 0; i < M; i++)
            {
                for (int j = 0; j < N; j++)
                    multiplied[i, j] = matrix[i, j] * v;
            }

            return multiplied;
        }

        public static double[,] Add(double[,] matrix1, double[,] matrix2)
        {
            int M = matrix1.GetLength(0);
            int N = matrix1.GetLength(1);

            if (M != matrix2.GetLength(0) || N != matrix2.GetLength(1))
                throw new ArgumentException("Two matrices should be the same dimension to add.");

            double[,] sum = new double[M, N];
            for (int i = 0; i < M; i++)
            {
                for (int j = 0; j < N; j++)
                    sum[i, j] = matrix1[i, j] + matrix2[i, j];

            }

            return sum;
        }

        public static double[,] Subtract(double[,] matrix1, double[,] matrix2)
        {
            int M = matrix1.GetLength(0);
            int N = matrix1.GetLength(1);

            if (M != matrix2.GetLength(0) || N != matrix2.GetLength(1))
                throw new ArgumentException("Two matrices should be the same dimension.");

            double[,] sum = new double[M, N];
            for (int i = 0; i < M; i++)
            {
                for (int j = 0; j < N; j++)
                    sum[i, j] = matrix1[i, j] - matrix2[i, j];

            }

            return sum;
        }

        public static double[,] Transpose(double[,] matrix)
        {
            int M = matrix.GetLength(0);
            int N = matrix.GetLength(1);

            double[,] transposed = new double[N, M];
            for (int i = 0; i < M; i++)
            {
                for (int j = 0; j < N; j++)
                {
                    transposed[j, i] = matrix[i, j];
                }
            }
            return transposed;
        }

        public static double[,] Inverse(double[,] matrix)
        {
		    return MultiplyScalar(Transpose(Cofactor(matrix)), DMath.SafeInv(Determinant(matrix)));
        }

        public static double Determinant(double[,] matrix)
        {
            int M = matrix.GetLength(0);
            int N = matrix.GetLength(1);

            if (N != M)
                throw new ArgumentException("Matrix need to be square to find determinant.");

            if (M == 1)
                return matrix[0, 0];

            if (M == 2)
                return matrix[0, 0] * matrix[1, 1] - matrix[0, 1] * matrix[1, 0];

            double sum = 0.0;
            for (int i = 0; i < N; i++)
                sum += ChangeSign(i) * matrix[0, i] * Determinant(SubMatrix(matrix, 0, i));
            
            return sum;
        }

        public static double[,] Cofactor(double[,] matrix)
        {
            int M = matrix.GetLength(0);
            int N = matrix.GetLength(1);

            double[,] mat = new double[M, N];

            for (int i = 0; i < M; i++)
            {
                for (int j = 0; j < N; j++)
                {
                    mat[i, j] = ChangeSign(i) * ChangeSign(j) * Determinant(SubMatrix(matrix, i, j));
                }
            }

            return mat;
        }

        public static double[,] SubMatrix(double[,] matrix, int excluding_row, int excluding_col)
        {
            int M = matrix.GetLength(0);
            int N = matrix.GetLength(1);

            double[,] mat = new double[M - 1, N - 1];
            int r = -1;
            for (int i = 0; i < M; i++)
            {
                if (i == excluding_row)
                    continue;
                r++;
                int c = -1;
                for (int j = 0; j < N; j++)
                {
                    if (j == excluding_col)
                        continue;
                    mat[r, ++c] = matrix[i, j];
                }
            }

            return mat;
        }

        private static int ChangeSign(int i)
        {
            if (i % 2 == 0)
                return 1;
            return -1;
        }

    }
}


================================================
FILE: Assets/Common/LinearAlgebra/MatrixMxN.cs.meta
================================================
fileFormatVersion: 2
guid: d64ab62afd178ca4f9b734695ee8f4e6
timeCreated: 1514536270
licenseType: Free
MonoImporter:
  externalObjects: {}
  serializedVersion: 2
  defaultReferences: []
  executionOrder: 0
  icon: {instanceID: 0}
  userData: 
  assetBundleName: 
  assetBundleVariant: 


================================================
FILE: Assets/Common/LinearAlgebra/Quaternion3d.cs
================================================
using System;
using System.Runtime.InteropServices;

using Common.Core.Mathematics;

namespace Common.Core.LinearAlgebra
{
    /// <summary>
    /// A double precision quaternion.
    /// </summary>
	[StructLayout(LayoutKind.Sequential)]
    public struct Quaternion3d
	{
		
		public double x, y, z, w;

        public readonly static Quaternion3d Identity = new Quaternion3d(0, 0, 0, 1);

        public readonly static Quaternion3d Zero = new Quaternion3d(0, 0, 0, 0);

        /// <summary>
        /// A Quaternion from varibles.
        /// </summary>
        public Quaternion3d(double x, double y, double z, double w)
		{
			this.x = x;
		    this.y = y;
			this.z = z;
			this.w = w;
		}

        /// <summary>
        /// A Quaternion copied from a array.
        /// </summary>
		public Quaternion3d(double[] v)
		{
			this.x = v[0];
		    this.y = v[1];
			this.z = v[2];
			this.w = v[3];
		}

        /// <summary>
        /// The inverse of the quaternion.
        /// </summary>
        public Quaternion3d Inverse
        {
            get
            {
                return new Quaternion3d(-x, -y, -z, w);
            }
        }

        /// <summary>
        /// The length of the quaternion.
        /// </summary>
        double Length
        {
            get
            {
                double len = x * x + y * y + z * z + w * w;
                return DMath.SafeSqrt(len);
            }
        }

        /// <summary>
        /// The a normalized quaternion.
        /// </summary>
        public Quaternion3d Normalized
        {
            get
            {
                double inv = DMath.SafeInv(Length);
                return new Quaternion3d(x * inv, y * inv, z * inv, w * inv);
            }
        }

        /// <summary>
        /// Are these Quaternions equal.
        /// </summary>
        public static bool operator ==(Quaternion3d v1, Quaternion3d v2)
		{
			return (v1.x == v2.x && v1.y == v2.y && v1.z == v2.z && v1.w == v2.w);
		}
		
		/// <summary>
		/// Are these Quaternions not equal.
		/// </summary>
		public static bool operator !=(Quaternion3d v1, Quaternion3d v2)
		{
			return (v1.x != v2.x || v1.y != v2.y || v1.z != v2.z || v1.w != v2.w);
		}
		
		/// <summary>
		/// Are these Quaternions equal.
		/// </summary>
		public override bool Equals (object obj)
		{
			if(!(obj is Quaternion3d)) return false;
			
			Quaternion3d v = (Quaternion3d)obj;
			
			return this == v;
		}
		
		/// <summary>
		/// Quaternions hash code. 
		/// </summary>
		public override int GetHashCode()
		{
            double hashcode = 23;
            hashcode = (hashcode * 37) + x;
            hashcode = (hashcode * 37) + y;
            hashcode = (hashcode * 37) + z;
            hashcode = (hashcode * 37) + w;

            return unchecked((int)hashcode);
        }
		
		/// <summary>
		/// Quaternion as a string.
		/// </summary>
		public override string ToString()
		{
			return "(" + x + "," + y + "," + z + "," + w + ")";
		}

        /// <summary>
        /// A Quaternion from a vector axis and angle.
        /// The axis is the up direction and the angle is the rotation.
        /// </summary>
		public Quaternion3d(Vector3d axis, double angle)
		{
		    Vector3d axisN = axis.Normalized;
		    double a = angle * 0.5;
		    double sina = Math.Sin(a);
		    double cosa = Math.Cos(a);
		    x = axisN.x * sina;
		    y = axisN.y * sina;
		    z = axisN.z * sina;
		    w = cosa;
		}

        /// <summary>
        /// A quaternion with the rotation required to
        /// rotation from the from direction to the to direction.
        /// </summary>
        public Quaternion3d(Vector3d to, Vector3d from)
		{
		    Vector3d f = from.Normalized;
		    Vector3d t = to.Normalized;
		
		    double dotProdPlus1 = 1.0 + Vector3d.Dot(f, t);
		
		    if (dotProdPlus1 < DMath.EPS) 
			{
		        w = 0;
		        if (Math.Abs(f.x) < 0.6) 
				{
		            double norm = Math.Sqrt(1 - f.x * f.x);
		            x = 0;
		            y = f.z / norm;
		            z = -f.y / norm;
		        } 
				else if (Math.Abs(f.y) < 0.6) 
				{
		            double norm = Math.Sqrt(1 - f.y * f.y);
		            x = -f.z / norm;
		            y = 0;
		            z = f.x / norm;
		        } 
				else 
				{
		            double norm = Math.Sqrt(1 - f.z * f.z);
		            x = f.y / norm;
		            y = -f.x / norm;
		            z = 0;
		        }
		    } 
			else 
			{
		        double s = Math.Sqrt(0.5 * dotProdPlus1);
		        Vector3d tmp = (f.Cross(t)) / (2.0 * s);
		        x = tmp.x;
		        y = tmp.y;
		        z = tmp.z;
		        w = s;
		    }
		}
		
		/// <summary>
		/// Multiply two quaternions together.
		/// </summary>
		public static Quaternion3d operator*( Quaternion3d q1, Quaternion3d q2 )
		{
			return new Quaternion3d(q2.w * q1.x  + q2.x * q1.w  + q2.y * q1.z  - q2.z * q1.y,
		                			q2.w * q1.y  - q2.x * q1.z  + q2.y * q1.w  + q2.z * q1.x,
		                			q2.w * q1.z  + q2.x * q1.y  - q2.y * q1.x  + q2.z * q1.w,
		                			q2.w * q1.w  - q2.x * q1.x  - q2.y * q1.y  - q2.z * q1.z);
		}
		
        /// <summary>
        /// Multiply a quaternion and a vector together.
        /// </summary>
		public static Vector3d operator*(Quaternion3d q, Vector3d v)
		{
		    return q.ToMatrix3x3d() * v;
		}

        /// <summary>
        /// Convert to a double precision 3 dimension matrix.
        /// </summary>
		public Matrix3x3d ToMatrix3x3d()
		{
		    double 	xx = x * x,
		         	xy = x * y,
		        	xz = x * z,
		         	xw = x * w,
		         	yy = y * y,
		         	yz = y * z,
		         	yw = y * w,
		         	zz = z * z,
		         	zw = z * w;
			
			return new Matrix3x3d
			(
			 	1.0 - 2.0 * (yy + zz), 2.0 * (xy - zw), 2.0 * (xz + yw),
			 	2.0 * (xy + zw), 1.0 - 2.0 * (xx + zz), 2.0 * (yz - xw),
			 	2.0 * (xz - yw), 2.0 * (yz + xw), 1.0 - 2.0 * (xx + yy)
			);
		}

        /// <summary>
        /// Convert to a double precision 4 dimension matrix.
        /// </summary>
		public Matrix4x4d ToMatrix4x4d()
		{
			double 	xx = x * x,
					xy = x * y,
					xz = x * z,
					xw = x * w,
					yy = y * y,
					yz = y * z,
					yw = y * w,
					zz = z * z,
					zw = z * w;
			
			return new Matrix4x4d
			(
				1.0 - 2.0 * (yy + zz), 2.0 * (xy - zw), 2.0 * (xz + yw), 0.0,
				2.0 * (xy + zw), 1.0 - 2.0 * (xx + zz), 2.0 * (yz - xw), 0.0,
				2.0 * (xz - yw), 2.0 * (yz + xw), 1.0 - 2.0 * (xx + yy), 0.0,
				0.0, 0.0, 0.0, 1.0
			);
		}

        /// <summary>
        /// The normalize the quaternion.
        /// </summary>
		public void Normalize()
		{
		    double invLength = DMath.SafeInv(Length);
		    x *= invLength; 
			y *= invLength; 
			z *= invLength; 
			w *= invLength;
		}

        /// <summary>
        /// Slerp the quaternion by t.
        /// </summary>
		public static Quaternion3d Slerp(Quaternion3d from, Quaternion3d to, double t)
		{
            if (t <= 0.0) 
			{
                return from;
		    }
            else if (t >= 1.0) 
			{
                return to;
		    } 
			else 
			{
		        double cosom = from.x * to.x + from.y * to.y + from.z * to.z + from.w * to.w;
		        double absCosom = Math.Abs(cosom);
		
		        double scale0;
		        double scale1;
		
		        if (1.0 - absCosom > DMath.EPS) 
				{
		            double omega = DMath.SafeAcos(absCosom);
		            double sinom = 1.0 / Math.Sin( omega );
		            scale0 = Math.Sin( ( 1.0 - t ) * omega ) * sinom;
		            scale1 = Math.Sin( t * omega ) * sinom;
		        } 
				else 
				{
                    scale0 = 1.0 - t;
		            scale1 = t;
		        }

                Quaternion3d res = new Quaternion3d(scale0 * from.x + scale1 * to.x,
	                                                scale0 * from.y + scale1 * to.y,
	                                                scale0 * from.z + scale1 * to.z,
	                                                scale0 * from.w + scale1 * to.w);
				
		        return res.Normalized;
		    }
		}

        /// <summary>
        /// Create a rotation out of a vector.
        /// </summary>
        public static Quaternion3d FromEuler(Vector3d euler)
        {
            double degToRad = Math.PI / 180.0;

            double yaw = euler.x * degToRad;
            double pitch = euler.y * degToRad;
            double roll = euler.z * degToRad;
            double rollOver2 = roll * 0.5;
            double sinRollOver2 = Math.Sin(rollOver2);
            double cosRollOver2 = Math.Cos(rollOver2);
            double pitchOver2 = pitch * 0.5;
            double sinPitchOver2 = Math.Sin(pitchOver2);
            double cosPitchOver2 = Math.Cos(pitchOver2);
            double yawOver2 = yaw * 0.5;
            double sinYawOver2 = Math.Sin(yawOver2);
            double cosYawOver2 = Math.Cos(yawOver2);

            Quaternion3d result;
            result.x = cosYawOver2 * cosPitchOver2 * cosRollOver2 + sinYawOver2 * sinPitchOver2 * sinRollOver2;
            result.y = cosYawOver2 * cosPitchOver2 * sinRollOver2 - sinYawOver2 * sinPitchOver2 * cosRollOver2;
            result.z = cosYawOver2 * sinPitchOver2 * cosRollOver2 + sinYawOver2 * cosPitchOver2 * sinRollOver2;
            result.w = sinYawOver2 * cosPitchOver2 * cosRollOver2 - cosYawOver2 * sinPitchOver2 * sinRollOver2;
            return result;
        }

    }

}


























================================================
FILE: Assets/Common/LinearAlgebra/Quaternion3d.cs.meta
================================================
fileFormatVersion: 2
guid: c2b4193eee97e4649ad3948f8e99a317
timeCreated: 1514536270
licenseType: Free
MonoImporter:
  externalObjects: {}
  serializedVersion: 2
  defaultReferences: []
  executionOrder: 0
  icon: {instanceID: 0}
  userData: 
  assetBundleName: 
  assetBundleVariant: 


================================================
FILE: Assets/Common/LinearAlgebra/Quaternion3f.cs
================================================
using System;
using System.Runtime.InteropServices;

using Common.Core.Mathematics;

namespace Common.Core.LinearAlgebra
{
    /// <summary>
    /// A single precision quaternion.
    /// </summary>
    [StructLayout(LayoutKind.Sequential)]
    public struct Quaternion3f
    {

        public float x, y, z, w;

        public readonly static Quaternion3f Identity = new Quaternion3f(0, 0, 0, 1);

        public readonly static Quaternion3f Zero = new Quaternion3f(0, 0, 0, 0);

        /// <summary>
        /// A Quaternion from varibles.
        /// </summary>
        public Quaternion3f(float x, float y, float z, float w)
        {
            this.x = x;
            this.y = y;
            this.z = z;
            this.w = w;
        }

        /// <summary>
        /// A Quaternion copied from a array.
        /// </summary>
        public Quaternion3f(float[] v)
        {
            this.x = v[0];
            this.y = v[1];
            this.z = v[2];
            this.w = v[3];
        }

        /// <summary>
        /// The inverse of the quaternion.
        /// </summary>
        public Quaternion3f Inverse
        {
            get
            {
                return new Quaternion3f(-x, -y, -z, w);
            }
        }

        /// <summary>
        /// The length of the quaternion.
        /// </summary>
        float Length
        {
            get
            {
                float len = x * x + y * y + z * z + w * w;
                return FMath.SafeSqrt(len);
            }
        }

        /// <summary>
        /// The a normalized quaternion.
        /// </summary>
        public Quaternion3f Normalized
        {
            get
            {
                float inv = FMath.SafeInv(Length);
                return new Quaternion3f(x * inv, y * inv, z * inv, w * inv);
            }
        }

        /// <summary>
        /// Are these Quaternions equal.
        /// </summary>
        public static bool operator ==(Quaternion3f v1, Quaternion3f v2)
		{
			return (v1.x == v2.x && v1.y == v2.y && v1.z == v2.z && v1.w == v2.w);
		}
		
		/// <summary>
		/// Are these Quaternions not equal.
		/// </summary>
		public static bool operator !=(Quaternion3f v1, Quaternion3f v2)
		{
			return (v1.x != v2.x || v1.y != v2.y || v1.z != v2.z || v1.w != v2.w);
		}
		
		/// <summary>
		/// Are these Quaternions equal.
		/// </summary>
		public override bool Equals (object obj)
		{
			if(!(obj is Quaternion3f)) return false;
			
			Quaternion3f v = (Quaternion3f)obj;
			
			return this == v;
		}
		
		/// <summary>
		/// Quaternions hash code. 
		/// </summary>
		public override int GetHashCode()
		{
            float hashcode = 23;
            hashcode = (hashcode * 37) + x;
            hashcode = (hashcode * 37) + y;
            hashcode = (hashcode * 37) + z;
            hashcode = (hashcode * 37) + w;

            return unchecked((int)hashcode);
        }
		
		/// <summary>
		/// Quaternion as a string.
		/// </summary>
		public override string ToString()
		{
			return "(" + x + "," + y + "," + z + "," + w + ")";
		}

        /// <summary>
        /// A Quaternion from a vector axis and angle.
        /// The axis is the up direction and the angle is the rotation.
        /// </summary>
        public Quaternion3f(Vector3f axis, float angle)
        {
            Vector3f axisN = axis.Normalized;
            float a = angle * 0.5f;
			float sina = (float)Math.Sin(a);
			float cosa = (float)Math.Cos(a);
            x = axisN.x * sina;
            y = axisN.y * sina;
            z = axisN.z * sina;
            w = cosa;
        }

        /// <summary>
        /// A quaternion with the rotation required to
        /// rotation from the from direction to the to direction.
        /// </summary>
        public Quaternion3f(Vector3f to, Vector3f from)
        {
            Vector3f f = from.Normalized;
            Vector3f t = to.Normalized;

            float dotProdPlus1 = 1.0f + Vector3f.Dot(f, t);

            if (dotProdPlus1 < FMath.EPS)
            {
                w = 0;
                if (Math.Abs(f.x) < 0.6f)
                {
					float norm = (float)Math.Sqrt(1 - f.x * f.x);
                    x = 0;
                    y = f.z / norm;
                    z = -f.y / norm;
                }
                else if (Math.Abs(f.y) < 0.6f)
                {
					float norm = (float)Math.Sqrt(1 - f.y * f.y);
                    x = -f.z / norm;
                    y = 0;
                    z = f.x / norm;
                }
                else
                {
					float norm = (float)Math.Sqrt(1 - f.z * f.z);
                    x = f.y / norm;
                    y = -f.x / norm;
                    z = 0;
                }
            }
            else
            {
				float s = (float)Math.Sqrt(0.5f * dotProdPlus1);
                Vector3f tmp = (f.Cross(t)) / (2.0f * s);
                x = tmp.x;
                y = tmp.y;
                z = tmp.z;
                w = s;
            }
        }

        /// <summary>
        /// Multiply two quternions together.
        /// </summary>
		public static Quaternion3f operator *(Quaternion3f q1, Quaternion3f q2)
        {
			return new Quaternion3f(q2.w * q1.x + q2.x * q1.w + q2.y * q1.z - q2.z * q1.y,
                            		q2.w * q1.y - q2.x * q1.z + q2.y * q1.w + q2.z * q1.x,
                            		q2.w * q1.z + q2.x * q1.y - q2.y * q1.x + q2.z * q1.w,
                            		q2.w * q1.w - q2.x * q1.x - q2.y * q1.y - q2.z * q1.z);
        }

        /// <summary>
        /// Multiply a quaternion and a vector together.
        /// </summary>
		public static Vector3f operator *(Quaternion3f q, Vector3f v)
        {
            return q.ToMatrix3x3f() * v;
        }

        /// <summary>
        /// Convert to a single precision 3 dimension matrix.
        /// </summary>
        public Matrix3x3f ToMatrix3x3f()
        {
            float   xx = x * x,
                    xy = x * y,
                    xz = x * z,
                    xw = x * w,
                    yy = y * y,
                    yz = y * z,
                    yw = y * w,
                    zz = z * z,
                    zw = z * w;

            return new Matrix3x3f
            (
                1.0f - 2.0f * (yy + zz), 2.0f * (xy - zw), 2.0f * (xz + yw),
                2.0f * (xy + zw), 1.0f - 2.0f * (xx + zz), 2.0f * (yz - xw),
                2.0f * (xz - yw), 2.0f * (yz + xw), 1.0f - 2.0f * (xx + yy)
            );
        }

        /// <summary>
        /// Convert to a single precision 4 dimension matrix.
        /// </summary>
        public Matrix4x4f ToMatrix4x4f()
        {
            float   xx = x * x,
                    xy = x * y,
                    xz = x * z,
                    xw = x * w,
                    yy = y * y,
                    yz = y * z,
                    yw = y * w,
                    zz = z * z,
                    zw = z * w;

            return new Matrix4x4f
            (
                1.0f - 2.0f * (yy + zz), 2.0f * (xy - zw), 2.0f * (xz + yw), 0.0f,
                2.0f * (xy + zw), 1.0f - 2.0f * (xx + zz), 2.0f * (yz - xw), 0.0f,
                2.0f * (xz - yw), 2.0f * (yz + xw), 1.0f - 2.0f * (xx + yy), 0.0f,
                0.0f, 0.0f, 0.0f, 1.0f
            );
        }

        /// <summary>
        /// The normalize the quaternion.
        /// </summary>
        public void Normalize()
        {
            float invLength = FMath.SafeInv(Length);
            x *= invLength;
            y *= invLength;
            z *= invLength;
            w *= invLength;
        }

        /// <summary>
        /// Slerp the quaternion from the from rotation to the to rotation by t.
        /// </summary>
		public static Quaternion3f Slerp(Quaternion3f from, Quaternion3f to, float t)
        {
            if (t <= 0.0f)
            {
                return from;
            }
            else if (t >= 1.0f)
            {
                return to;
            }
            else
            {
                float cosom = from.x * to.x + from.y * to.y + from.z * to.z + from.w * to.w;
                float absCosom = Math.Abs(cosom);

                float scale0;
                float scale1;

                if ((1 - absCosom) > FMath.EPS)
                {
                    float omega = FMath.SafeAcos(absCosom);
					float sinom = 1.0f / (float)Math.Sin(omega);
					scale0 = (float)Math.Sin((1.0f - t) * omega) * sinom;
					scale1 = (float)Math.Sin(t * omega) * sinom;
                }
                else
                {
                    scale0 = 1 - t;
                    scale1 = t;
                }
                Quaternion3f res = new Quaternion3f(scale0 * from.x + scale1 * to.x,
                                                    scale0 * from.y + scale1 * to.y,
                                                    scale0 * from.z + scale1 * to.z,
                                                    scale0 * from.w + scale1 * to.w);

                return res.Normalized;
            }
        }

        /// <summary>
        /// Create a rotation out of a vector.
        /// </summary>
        public static Quaternion3f FromEuler(Vector3f euler)
        {
 
            float degToRad = (float)(Math.PI / 180.0);

            var yaw = euler.x * degToRad;
            var pitch = euler.y * degToRad;
            var roll = euler.z * degToRad;
            float rollOver2 = roll * 0.5f;
            float sinRollOver2 = (float)Math.Sin(rollOver2);
            float cosRollOver2 = (float)Math.Cos(rollOver2);
            float pitchOver2 = pitch * 0.5f;
            float sinPitchOver2 = (float)Math.Sin(pitchOver2);
            float cosPitchOver2 = (float)Math.Cos(pitchOver2);
            float yawOver2 = yaw * 0.5f;
            float sinYawOver2 = (float)Math.Sin(yawOver2);
            float cosYawOver2 = (float)Math.Cos(yawOver2);

            Quaternion3f result;
            result.x = cosYawOver2 * cosPitchOver2 * cosRollOver2 + sinYawOver2 * sinPitchOver2 * sinRollOver2;
            result.y = cosYawOver2 * cosPitchOver2 * sinRollOver2 - sinYawOver2 * sinPitchOver2 * cosRollOver2;
            result.z = cosYawOver2 * sinPitchOver2 * cosRollOver2 + sinYawOver2 * cosPitchOver2 * sinRollOver2;
            result.w = sinYawOver2 * cosPitchOver2 * cosRollOver2 - cosYawOver2 * sinPitchOver2 * sinRollOver2;
            return result;

        }


    }

}


























================================================
FILE: Assets/Common/LinearAlgebra/Quaternion3f.cs.meta
================================================
fileFormatVersion: 2
guid: da6fc536acb153944a010e07ae652bf9
timeCreated: 1514536271
licenseType: Free
MonoImporter:
  externalObjects: {}
  serializedVersion: 2
  defaultReferences: []
  executionOrder: 0
  icon: {instanceID: 0}
  userData: 
  assetBundleName: 
  assetBundleVariant: 


================================================
FILE: Assets/Common/LinearAlgebra/Vector2d.cs
================================================
using System;
using System.Collections;
using System.Runtime.InteropServices;

using Common.Core.Mathematics;

namespace Common.Core.LinearAlgebra
{
    /// <summary>
    /// A 2d double precision vector.
    /// </summary>
    [StructLayout(LayoutKind.Sequential)]
    public struct Vector2d
	{
		public double x, y;

        /// <summary>
        /// The unit x vector.
        /// </summary>
	    public readonly static Vector2d UnitX = new Vector2d(1, 0);

        /// <summary>
        /// The unit y vector.
        /// </summary>
	    public readonly static Vector2d UnitY = new Vector2d(0, 1);

        /// <summary>
        /// A vector of zeros.
        /// </summary>
	    public readonly static Vector2d Zero = new Vector2d(0);

        /// <summary>
        /// A vector of ones.
        /// </summary>
	    public readonly static Vector2d One = new Vector2d(1);

        /// <summary>
        /// A vector of positive infinity.
        /// </summary>
        public readonly static Vector2d PositiveInfinity = new Vector2d(double.PositiveInfinity);

        /// <summary>
        /// A vector of negative infinity.
        /// </summary>
        public readonly static Vector2d NegativeInfinity = new Vector2d(double.NegativeInfinity);

        /// <summary>
        /// Convert to a 3 dimension vector.
        /// </summary>
        public Vector3d x0z
        {
            get { return new Vector3d(x, 0, y); }
        }

        /// <summary>
        /// A vector all with the value v.
        /// </summary>
        public Vector2d(double v) 
		{
			this.x = v; 
			this.y = v; 
		}

        /// <summary>
        /// A vector from the varibles.
        /// </summary>
		public Vector2d(double x, double y) 
		{
			this.x = x; 
			this.y = y; 
		}

        public double this[int i]
        {
            get
            {
                switch (i)
                {
                    case 0: return x;
                    case 1: return y;
                    default: throw new IndexOutOfRangeException("Vector2d index out of range: " + i);
                }
            }
            set
            {
                switch (i)
                {
                    case 0: x = value; break;
                    case 1: y = value; break;
                    default: throw new IndexOutOfRangeException("Vector2d index out of range: " + i);
                }
            }
        }

        /// <summary>
        /// The length of the vector.
        /// </summary>
        public double Magnitude
        {
            get
            {
                return DMath.SafeSqrt(SqrMagnitude);
            }
        }

        /// <summary>
        /// The length of the vector squared.
        /// </summary>
		public double SqrMagnitude
        {
            get
            {
                return (x * x + y * y);
            }
        }

        /// <summary>
        /// The vector normalized.
        /// </summary>
        public Vector2d Normalized
        {
            get
            {
                double invLength = DMath.SafeInvSqrt(1.0, x * x + y * y);
                return new Vector2d(x * invLength, y * invLength);
            }
        }

        /// <summary>
        /// Counter clock-wise perpendicular.
        /// </summary>
        public Vector2d PerpendicularCCW
        {
            get
            {
                return new Vector2d(-y, x);
            }
        }

        /// <summary>
        /// Clock-wise perpendicular.
        /// </summary>
        public Vector2d PerpendicularCW
        {
            get
            {
                return new Vector2d(y, -x);
            }
        }

        /// <summary>
        /// The vectors absolute values.
        /// </summary>
        public Vector2d Absolute
        {
            get
            {
                return new Vector2d(Math.Abs(x), Math.Abs(y));
            }
        }

        /// <summary>
        /// Add two vectors.
        /// </summary>
        public static Vector2d operator +(Vector2d v1, Vector2d v2)
        {
            return new Vector2d(v1.x + v2.x, v1.y + v2.y);
        }

        /// <summary>
        /// Add vector and scalar.
        /// </summary>
        public static Vector2d operator +(Vector2d v1, double s)
        {
            return new Vector2d(v1.x + s, v1.y + s);
        }

        /// <summary>
        /// Add vector and scalar.
        /// </summary>
        public static Vector2d operator +(double s, Vector2d v1)
        {
            return new Vector2d(v1.x + s, v1.y + s);
        }

        /// <summary>
        /// Subtract two vectors.
        /// </summary>
        public static Vector2d operator -(Vector2d v1, Vector2d v2)
        {
            return new Vector2d(v1.x - v2.x, v1.y - v2.y);
        }

        /// <summary>
        /// Subtract vector and scalar.
        /// </summary>
        public static Vector2d operator -(Vector2d v1, double s)
        {
            return new Vector2d(v1.x - s, v1.y - s);
        }

        /// <summary>
        /// Subtract vector and scalar.
        /// </summary>
        public static Vector2d operator -(double s, Vector2d v1)
        {
            return new Vector2d(v1.x - s, v1.y - s);
        }

        /// <summary>
        /// Multiply two vectors.
        /// </summary>
        public static Vector2d operator *(Vector2d v1, Vector2d v2)
        {
            return new Vector2d(v1.x * v2.x, v1.y * v2.y);
        }

        /// <summary>
        /// Multiply a vector and a scalar.
        /// </summary>
        public static Vector2d operator *(Vector2d v, double s)
        {
            return new Vector2d(v.x * s, v.y * s);
        }

        /// <summary>
        /// Multiply a vector and a scalar.
        /// </summary>
        public static Vector2d operator *(double s, Vector2d v)
        {
            return new Vector2d(v.x * s, v.y * s);
        }

        /// <summary>
        /// Divide two vectors.
        /// </summary>
        public static Vector2d operator /(Vector2d v1, Vector2d v2)
        {
            return new Vector2d(v1.x / v2.x, v1.y / v2.y);
        }

        /// <summary>
        /// Divide a vector and a scalar.
        /// </summary>
        public static Vector2d operator /(Vector2d v, double s)
        {
            return new Vector2d(v.x / s, v.y / s);
        }

		/// <summary>
		/// Are these vectors equal.
		/// </summary>
		public static bool operator ==(Vector2d v1, Vector2d v2)
		{
			return (v1.x == v2.x && v1.y == v2.y);
		}
		
		/// <summary>
		/// Are these vectors not equal.
		/// </summary>
		public static bool operator !=(Vector2d v1, Vector2d v2)
		{
			return (v1.x != v2.x || v1.y != v2.y);
		}
		
		/// <summary>
		/// Are these vectors equal.
		/// </summary>
		public override bool Equals (object obj)
		{
			if(!(obj is Vector2d)) return false;
			
			Vector2d v = (Vector2d)obj;
			
			return this == v;
		}

		/// <summary>
		/// Are these vectors equal given the error.
		/// </summary>
		public bool EqualsWithError(Vector2d v, double eps)
		{
			if(Math.Abs(x-v.x)> eps) return false;
			if(Math.Abs(y-v.y)> eps) return false;
			return true;
		}

        /// <summary>
        /// Are these vectors equal.
        /// </summary>
        public bool Equals(Vector2d v)
        {
            return this == v;
        }

        /// <summary>
        /// Vectors hash code. 
        /// </summary>
        public override int GetHashCode()
        {
            double hashcode = 23;

            hashcode = (hashcode * 37) + x;
            hashcode = (hashcode * 37) + y;

			return unchecked((int)hashcode);
        }
		
	    /// <summary>
	    /// Vector as a string.
	    /// </summary>
		public override string ToString()
	   	{
			return x + "," + y;
	   	}

        /// <summary>
        /// Vector from a string.
        /// </summary>
        static public Vector2d FromString(string s)
        {
            Vector2d v = new Vector2d();

            try
            {
                string[] separators = new string[] { "," };
                string[] result = s.Split(separators, StringSplitOptions.None);

                v.x = double.Parse(result[0]);
                v.y = double.Parse(result[1]);
            }
            catch { }

            return v;
        }

		/// <summary>
		/// The dot product of two vectors.
		/// </summary>
		public static double Dot(Vector2d v0, Vector2d v1)
		{
			return (v0.x*v1.x + v0.y*v1.y);
		}

        /// <summary>
        /// Normalize the vector.
        /// </summary>
		public void Normalize()
		{
	    	double invLength = DMath.SafeInvSqrt(1.0, x*x + y*y);
	    	x *= invLength;
			y *= invLength;
		}

        /// <summary>
        /// Cross two vectors.
        /// </summary>
        public static double Cross(Vector2d v0, Vector2d v1)
        {
            return v0.x * v1.y - v0.y * v1.x;
        }

        /// <summary>
        /// Distance between two vectors.
        /// </summary>
        public static double Distance(Vector2d v0, Vector2d v1)
        {
            return DMath.SafeSqrt(SqrDistance(v0, v1));
        }

        /// <summary>
        /// Square distance between two vectors.
        /// </summary>
        public static double SqrDistance(Vector2d v0, Vector2d v1)
        {
            double x = v0.x - v1.x;
            double y = v0.y - v1.y;
            return x * x + y * y;
        }

        /// <summary>
        /// Angle between two vectors in degrees from 180 to -180.
        /// </summary>
        public static double Angle180(Vector2d a, Vector2d b)
        {
            double m = a.Magnitude * b.Magnitude;
            if (m == 0.0) return 0;

            double angle = Dot(a, b) / m;

            return DMath.SafeAcos(angle) * DMath.Rad2Deg;
        }

        /// <summary>
        /// Angle between two vectors in degrees from 0 to 360;
        /// </summary>
        public static double AngleCCW(Vector2d a, Vector2d b)
        {
            double angle = Math.Atan2(a.y, a.x) - Math.Atan2(b.y, b.x);
       
            if (angle <= 0.0)
                angle = Math.PI * 2.0 + angle;

            return 360.0 - angle * DMath.Rad2Deg;
        }

        /// <summary>
        /// The minimum value between s and each component in vector.
        /// </summary>
        public void Min(double s)
		{
			x = Math.Min(x, s);
			y = Math.Min(y, s);
		}

        /// <summary>
        /// The minimum value between each component in vectors.
        /// </summary>
        public void Min(Vector2d v)
        {
            x = Math.Min(x, v.x);
            y = Math.Min(y, v.y);
        }
		
		/// <summary>
		/// The maximum value between s and each component in vector.
		/// </summary>
        public void Max(double s)
		{
			x = Math.Max(x, s);
			y = Math.Max(y, s);
		}

        /// <summary>
        /// The maximum value between each component in vectors.
        /// </summary>
        public void Max(Vector2d v)
        {
            x = Math.Max(x, v.x);
            y = Math.Max(y, v.y);
        }

        /// <summary>
        /// The absolute vector.
        /// </summary>
        public void Abs()
        {
            x = Math.Abs(x);
            y = Math.Abs(y);
        }

        /// <summary>
        /// Clamp the each component to specified min and max.
        /// </summary>
        public void Clamp(double min, double max)
		{
			x = Math.Max(Math.Min(x, max), min);
			y = Math.Max(Math.Min(y, max), min);
		}

        /// <summary>
        /// Clamp the each component to specified min and max.
        /// </summary>
        public void Clamp(Vector2d min, Vector2d max)
        {
            x = Math.Max(Math.Min(x, max.x), min.x);
            y = Math.Max(Math.Min(y, max.y), min.y);
        }

        /// <summary>
        /// Lerp between two vectors.
        /// </summary>
        public static Vector2d Lerp(Vector2d from, Vector2d to, double t)
        {
            if (t < 0.0) t = 0.0;
            if (t > 1.0) t = 1.0;

            if (t == 0.0) return from;
            if (t == 1.0) return to;

            double t1 = 1.0 - t;
            Vector2d v = new Vector2d();
            v.x = from.x * t1 + to.x * t;
            v.y = from.y * t1 + to.y * t;
            return v;
        }

        /// <summary>
        /// Slerp between two vectors arc.
        /// </summary>
        public static Vector2d Slerp(Vector2d from, Vector2d to, double t)
        {
            if (t < 0.0) t = 0.0;
            if (t > 1.0) t = 1.0;

            if (t == 0.0) return from;
            if (t == 1.0) return to;
            if (to.x == from.x && to.y == from.y) return to;

            double m = from.Magnitude * to.Magnitude;
            if (DMath.IsZero(m)) return Vector2d.Zero;

            double theta = Math.Acos(Dot(from, to) / m);

            if (theta == 0.0) return to;

            double sinTheta = Math.Sin(theta);
            double st1 = Math.Sin((1.0 - t) * theta) / sinTheta;
            double st = Math.Sin(t * theta) / sinTheta;

            Vector2d v = new Vector2d();
            v.x = from.x * st1 + to.x * st;
            v.y = from.y * st1 + to.y * st;

            return v;
        }

    }

}




































================================================
FILE: Assets/Common/LinearAlgebra/Vector2d.cs.meta
================================================
fileFormatVersion: 2
guid: c1b7dd742e9f9aa49957980a1f94d794
timeCreated: 1514536270
licenseType: Free
MonoImporter:
  externalObjects: {}
  serializedVersion: 2
  defaultReferences: []
  executionOrder: 0
  icon: {instanceID: 0}
  userData: 
  assetBundleName: 
  assetBundleVariant: 


================================================
FILE: Assets/Common/LinearAlgebra/Vector2f.cs
================================================
using System;
using System.Collections;
using System.Runtime.InteropServices;

using Common.Core.Mathematics;

namespace Common.Core.LinearAlgebra
{
    /// <summary>
    /// A 2d single precision vector.
    /// </summary>
    [StructLayout(LayoutKind.Sequential)]
    public struct Vector2f
    {
        public float x, y;

        /// <summary>
        /// The unit x vector.
        /// </summary>
        public readonly static Vector2f UnitX = new Vector2f(1, 0);

        /// <summary>
        /// The unit y vector.
        /// </summary>
	    public readonly static Vector2f UnitY = new Vector2f(0, 1);

        /// <summary>
        /// A vector of zeros.
        /// </summary>
	    public readonly static Vector2f Zero = new Vector2f(0);

        /// <summary>
        /// A vector of ones.
        /// </summary>
	    public
Download .txt
gitextract_fo5zd9vd/

├── .gitignore
├── Assets/
│   ├── Common/
│   │   ├── Decomposition/
│   │   │   ├── Decomposition2x2d.cs
│   │   │   ├── Decomposition2x2d.cs.meta
│   │   │   ├── Decomposition2x2f.cs
│   │   │   ├── Decomposition2x2f.cs.meta
│   │   │   ├── Decomposition3x3d.cs
│   │   │   ├── Decomposition3x3d.cs.meta
│   │   │   ├── Decomposition3x3f.cs
│   │   │   └── Decomposition3x3f.cs.meta
│   │   ├── Decomposition.meta
│   │   ├── LinearAlgebra/
│   │   │   ├── Matrix2x2d.cs
│   │   │   ├── Matrix2x2d.cs.meta
│   │   │   ├── Matrix2x2f.cs
│   │   │   ├── Matrix2x2f.cs.meta
│   │   │   ├── Matrix3x3d.cs
│   │   │   ├── Matrix3x3d.cs.meta
│   │   │   ├── Matrix3x3f.cs
│   │   │   ├── Matrix3x3f.cs.meta
│   │   │   ├── Matrix4x4d.cs
│   │   │   ├── Matrix4x4d.cs.meta
│   │   │   ├── Matrix4x4f.cs
│   │   │   ├── Matrix4x4f.cs.meta
│   │   │   ├── MatrixMxN.cs
│   │   │   ├── MatrixMxN.cs.meta
│   │   │   ├── Quaternion3d.cs
│   │   │   ├── Quaternion3d.cs.meta
│   │   │   ├── Quaternion3f.cs
│   │   │   ├── Quaternion3f.cs.meta
│   │   │   ├── Vector2d.cs
│   │   │   ├── Vector2d.cs.meta
│   │   │   ├── Vector2f.cs
│   │   │   ├── Vector2f.cs.meta
│   │   │   ├── Vector2i.cs
│   │   │   ├── Vector2i.cs.meta
│   │   │   ├── Vector3d.cs
│   │   │   ├── Vector3d.cs.meta
│   │   │   ├── Vector3f.cs
│   │   │   ├── Vector3f.cs.meta
│   │   │   ├── Vector3i.cs
│   │   │   ├── Vector3i.cs.meta
│   │   │   ├── Vector4d.cs
│   │   │   ├── Vector4d.cs.meta
│   │   │   ├── Vector4f.cs
│   │   │   ├── Vector4f.cs.meta
│   │   │   ├── Vector4i.cs
│   │   │   └── Vector4i.cs.meta
│   │   ├── LinearAlgebra.meta
│   │   ├── Mathematics/
│   │   │   ├── DMath.cs
│   │   │   ├── DMath.cs.meta
│   │   │   ├── FMath.cs
│   │   │   ├── FMath.cs.meta
│   │   │   ├── IMath.cs
│   │   │   └── IMath.cs.meta
│   │   └── Mathematics.meta
│   ├── Common.meta
│   ├── FEM2D/
│   │   ├── Demo.unity
│   │   ├── Demo.unity.meta
│   │   ├── Materials/
│   │   │   ├── TextureMaterial.mat
│   │   │   ├── TextureMaterial.mat.meta
│   │   │   ├── TextureShader.shader
│   │   │   └── TextureShader.shader.meta
│   │   ├── Materials.meta
│   │   ├── Scripts/
│   │   │   ├── CreateCantileverBeam.cs
│   │   │   ├── CreateCantileverBeam.cs.meta
│   │   │   ├── CreateFromImage.cs
│   │   │   ├── CreateFromImage.cs.meta
│   │   │   ├── CreateRandomConvex.cs
│   │   │   ├── CreateRandomConvex.cs.meta
│   │   │   ├── CreateTorus.cs
│   │   │   ├── CreateTorus.cs.meta
│   │   │   ├── DelaunayTriangulation.cs
│   │   │   ├── DelaunayTriangulation.cs.meta
│   │   │   ├── FEMDemo.cs
│   │   │   ├── FEMDemo.cs.meta
│   │   │   ├── FEMElement.cs
│   │   │   ├── FEMElement.cs.meta
│   │   │   ├── FEMFractureEvent.cs
│   │   │   ├── FEMFractureEvent.cs.meta
│   │   │   ├── FEMParticle.cs
│   │   │   ├── FEMParticle.cs.meta
│   │   │   ├── FEMScene.cs
│   │   │   ├── FEMScene.cs.meta
│   │   │   ├── Mesher.cs
│   │   │   ├── Mesher.cs.meta
│   │   │   ├── Triangle.cs
│   │   │   └── Triangle.cs.meta
│   │   ├── Scripts.meta
│   │   ├── Textures/
│   │   │   ├── armadillo.png.meta
│   │   │   ├── bunny.png.meta
│   │   │   └── donut1.png.meta
│   │   └── Textures.meta
│   └── FEM2D.meta
├── LICENSE
├── Packages/
│   ├── manifest.json
│   └── packages-lock.json
├── ProjectSettings/
│   ├── AudioManager.asset
│   ├── ClusterInputManager.asset
│   ├── DynamicsManager.asset
│   ├── EditorBuildSettings.asset
│   ├── EditorSettings.asset
│   ├── GraphicsSettings.asset
│   ├── InputManager.asset
│   ├── NavMeshAreas.asset
│   ├── PackageManagerSettings.asset
│   ├── Physics2DSettings.asset
│   ├── PresetManager.asset
│   ├── ProjectSettings.asset
│   ├── ProjectVersion.txt
│   ├── QualitySettings.asset
│   ├── TagManager.asset
│   ├── TimeManager.asset
│   ├── UnityConnectSettings.asset
│   ├── VFXManager.asset
│   ├── VersionControlSettings.asset
│   └── XRSettings.asset
└── README.md
Download .txt
SYMBOL INDEX (514 symbols across 37 files)

FILE: Assets/Common/Decomposition/Decomposition2x2d.cs
  class Decomposition2x2d (line 8) | public static class Decomposition2x2d
    method QRDecomposition (line 11) | public static Matrix2x2d QRDecomposition(Matrix2x2d m)
    method PolarDecomposition (line 22) | public static Matrix2x2d PolarDecomposition(Matrix2x2d m)
    method EigenDecomposition (line 36) | public static void EigenDecomposition(Matrix2x2d m, out double e1, out...
    method SolveQuadratic (line 46) | private static bool SolveQuadratic(double a, double b, double c, out d...

FILE: Assets/Common/Decomposition/Decomposition2x2f.cs
  class Decomposition2x2f (line 8) | public static class Decomposition2x2f
    method QRDecomposition (line 11) | public static Matrix2x2f QRDecomposition(Matrix2x2f m)
    method PolarDecomposition (line 22) | public static Matrix2x2f PolarDecomposition(Matrix2x2f m)
    method EigenDecomposition (line 36) | public static void EigenDecomposition(Matrix2x2f m, out float e1, out ...
    method SolveQuadratic (line 46) | private static bool SolveQuadratic(float a, float b, float c, out floa...

FILE: Assets/Common/Decomposition/Decomposition3x3d.cs
  class Decomposition3x3d (line 8) | public static class Decomposition3x3d
    method JacobiRotate (line 14) | public static void JacobiRotate(ref Matrix3x3d A, ref Matrix3x3d R, in...
    method EigenDecomposition (line 53) | public static void EigenDecomposition(Matrix3x3d A, out Matrix3x3d eig...
    method PolarDecomposition (line 90) | public static void PolarDecomposition(Matrix3x3d A, out Matrix3x3d R, ...
    method OneNorm (line 165) | public static double OneNorm(Matrix3x3d A)
    method InfNorm (line 184) | public static double InfNorm(Matrix3x3d A)
    method PolarDecompositionStable (line 203) | public static void PolarDecompositionStable(Matrix3x3d M, double toler...
    method SVDWithInversionHandling (line 295) | public static void SVDWithInversionHandling(Matrix3x3d A, out Vector3d...

FILE: Assets/Common/Decomposition/Decomposition3x3f.cs
  class Decomposition3x3f (line 8) | public static class Decomposition3x3f
    method JacobiRotate (line 14) | public static void JacobiRotate(ref Matrix3x3f A, ref Matrix3x3f R, in...
    method EigenDecomposition (line 53) | public static void EigenDecomposition(Matrix3x3f A, out Matrix3x3f eig...
    method PolarDecomposition (line 90) | public static void PolarDecomposition(Matrix3x3f A, out Matrix3x3f R, ...
    method OneNorm (line 165) | private static float OneNorm(Matrix3x3f A)
    method InfNorm (line 184) | private static float InfNorm(Matrix3x3f A)
    method PolarDecompositionStable (line 203) | public static void PolarDecompositionStable(Matrix3x3f M, float tolera...
    method SVDWithInversionHandling (line 293) | public static void SVDWithInversionHandling(Matrix3x3f A, out Vector3f...

FILE: Assets/Common/LinearAlgebra/Matrix2x2d.cs
  type Matrix2x2d (line 13) | [StructLayout(LayoutKind.Sequential)]
    method Matrix2x2d (line 29) | public Matrix2x2d(double m00, double m01, double m10, double m11)
    method Matrix2x2d (line 38) | public Matrix2x2d(double v)
    method Matrix2x2d (line 47) | public Matrix2x2d(double[,] m)
    method Matrix2x2d (line 56) | public Matrix2x2d(double[] m)
    method Equals (line 284) | public override bool Equals (object obj)
    method Equals (line 296) | public bool Equals(Matrix2x2d mat)
    method EqualsWithError (line 304) | public bool EqualsWithError(Matrix2x2d m, double eps)
    method GetHashCode (line 317) | public override int GetHashCode()
    method ToString (line 330) | public override string ToString()
    method TryInverse (line 340) | public bool TryInverse(ref Matrix2x2d mInv)
    method GetColumn (line 359) | public Vector2d GetColumn(int iCol)
    method SetColumn (line 367) | public void SetColumn(int iCol, Vector2d v)
    method GetRow (line 376) | public Vector2d GetRow(int iRow)
    method SetRow (line 384) | public void SetRow(int iRow, Vector2d v)
    method Rotate (line 393) | static public Matrix2x2d Rotate(double angle)
    method ToMatrix3x3d (line 405) | public Matrix3x3d ToMatrix3x3d()

FILE: Assets/Common/LinearAlgebra/Matrix2x2f.cs
  type Matrix2x2f (line 12) | [StructLayout(LayoutKind.Sequential)]
    method Matrix2x2f (line 28) | public Matrix2x2f(float m00, float m01, float m10, float m11)
    method Matrix2x2f (line 37) | public Matrix2x2f(float v)
    method Matrix2x2f (line 46) | public Matrix2x2f(float[,] m)
    method Matrix2x2f (line 55) | public Matrix2x2f(float[] m)
    method Equals (line 283) | public override bool Equals (object obj)
    method Equals (line 295) | public bool Equals(Matrix2x2f mat)
    method EqualsWithError (line 303) | public bool EqualsWithError(Matrix2x2f m, float eps)
    method GetHashCode (line 316) | public override int GetHashCode()
    method ToString (line 329) | public override string ToString()
    method TryInverse (line 339) | public bool TryInverse(ref Matrix2x2f mInv)
    method GetColumn (line 358) | public Vector2f GetColumn(int iCol)
    method SetColumn (line 366) | public void SetColumn(int iCol, Vector2f v)
    method GetRow (line 375) | public Vector2f GetRow(int iRow)
    method SetRow (line 383) | public void SetRow(int iRow, Vector2f v)
    method Rotate (line 392) | static public Matrix2x2f Rotate(float angle)
    method ToMatrix3x3f (line 404) | public Matrix3x3f ToMatrix3x3f()

FILE: Assets/Common/LinearAlgebra/Matrix3x3d.cs
  type Matrix3x3d (line 12) | [StructLayout(LayoutKind.Sequential)]
    method Matrix3x3d (line 30) | public Matrix3x3d(double m00, double m01, double m02,
    method Matrix3x3d (line 43) | public Matrix3x3d(double v)
    method Matrix3x3d (line 53) | public Matrix3x3d(double[,] m)
    method Matrix3x3d (line 63) | public Matrix3x3d(double[] m)
    method Equals (line 377) | public override bool Equals(object obj)
    method Equals (line 389) | public bool Equals(Matrix3x3d mat)
    method EqualsWithError (line 397) | public bool EqualsWithError(Matrix3x3d m, double eps)
    method GetHashCode (line 417) | public override int GetHashCode()
    method ToString (line 430) | public override string ToString()
    method TryInverse (line 444) | public bool TryInverse(out Matrix3x3d mInv)
    method GetColumn (line 476) | public Vector3d GetColumn(int iCol)
    method SetColumn (line 484) | public void SetColumn(int iCol, Vector3d v)
    method GetRow (line 494) | public Vector3d GetRow(int iRow)
    method SetRow (line 502) | public void SetRow(int iRow, Vector3d v)
    method ToMatrix4x4d (line 512) | public Matrix4x4d ToMatrix4x4d()
    method Translate (line 523) | static public Matrix3x3d Translate(Vector2d v)
    method Scale (line 533) | static public Matrix3x3d Scale(Vector2d v)
    method Scale (line 544) | static public Matrix3x3d Scale(double s)
    method RotateX (line 555) | static public Matrix3x3d RotateX(double angle)
    method RotateY (line 568) | static public Matrix3x3d RotateY(double angle)
    method RotateZ (line 581) | static public Matrix3x3d RotateZ(double angle)
    method Rotate (line 594) | static public Matrix3x3d Rotate(Vector3d euler)

FILE: Assets/Common/LinearAlgebra/Matrix3x3f.cs
  type Matrix3x3f (line 12) | [StructLayout(LayoutKind.Sequential)]
    method Matrix3x3f (line 30) | public Matrix3x3f(float m00, float m01, float m02,
    method Matrix3x3f (line 43) | public Matrix3x3f(float v)
    method Matrix3x3f (line 53) | public Matrix3x3f(float[,] m)
    method Matrix3x3f (line 63) | public Matrix3x3f(float[] m)
    method Equals (line 377) | public override bool Equals (object obj)
    method Equals (line 389) | public bool Equals(Matrix3x3f mat)
    method EqualsWithError (line 397) | public bool EqualsWithError(Matrix3x3f m, float eps)
    method GetHashCode (line 417) | public override int GetHashCode()
    method ToString (line 430) | public override string ToString()
    method TryInverse (line 444) | public bool TryInverse(out Matrix3x3f mInv)
    method GetColumn (line 476) | public Vector3f GetColumn(int iCol)
    method SetColumn (line 484) | public void SetColumn(int iCol, Vector3f v)
    method GetRow (line 494) | public Vector3f GetRow(int iRow)
    method SetRow (line 502) | public void SetRow(int iRow, Vector3f v)
    method ToMatrix4x4f (line 512) | public Matrix4x4f ToMatrix4x4f()
    method Translate (line 523) | static public Matrix3x3f Translate(Vector2f v)
    method Scale (line 533) | static public Matrix3x3f Scale(Vector2f v)
    method Scale (line 543) | static public Matrix3x3f Scale(float s)
    method RotateX (line 553) | static public Matrix3x3f RotateX(float angle)
    method RotateY (line 566) | static public Matrix3x3f RotateY(float angle)
    method RotateZ (line 579) | static public Matrix3x3f RotateZ(float angle)
    method Rotate (line 592) | static public Matrix3x3f Rotate(Vector3f euler)

FILE: Assets/Common/LinearAlgebra/Matrix4x4d.cs
  type Matrix4x4d (line 12) | [StructLayout(LayoutKind.Sequential)]
    method Matrix4x4d (line 35) | public Matrix4x4d(double m00, double m01, double m02, double m03,
    method Matrix4x4d (line 50) | public Matrix4x4d(double v)
    method Matrix4x4d (line 61) | public Matrix4x4d(double[,] m)
    method Matrix4x4d (line 72) | public Matrix4x4d(double[] m)
    method Equals (line 528) | public override bool Equals (object obj)
    method Equals (line 540) | public bool Equals (Matrix4x4d mat)
    method EqualsWithError (line 548) | public bool EqualsWithError(Matrix4x4d m, double eps)
    method GetHashCode (line 576) | public override int GetHashCode()
    method ToString (line 589) | public override string ToString()
    method Minor (line 600) | private double Minor(int r0, int r1, int r2, int c0, int c1, int c2)
    method TryInverse (line 611) | public bool TryInverse(out Matrix4x4d mInv)
    method GetColumn (line 628) | public Vector4d GetColumn(int iCol)
    method SetColumn (line 636) | public void SetColumn(int iCol, Vector4d v)
    method FlipColumn (line 647) | public void FlipColumn(int iCol)
    method GetRow (line 658) | public Vector4d GetRow(int iRow)
    method SetRow (line 666) | public void SetRow(int iRow, Vector4d v)
    method FlipRow (line 677) | public void FlipRow(int iRow)
    method ToMatrix3x3d (line 688) | public Matrix3x3d ToMatrix3x3d()
    method TranslateRotateScale (line 702) | static public Matrix4x4d TranslateRotateScale(Vector3d t, Quaternion3d...
    method TranslateRotate (line 714) | static public Matrix4x4d TranslateRotate(Vector3d t, Quaternion3d r)
    method TranslateScale (line 725) | static public Matrix4x4d TranslateScale(Vector3d t, Vector3d s)
    method RotateScale (line 736) | static public Matrix4x4d RotateScale(Quaternion3d r, Vector3d s)
    method Translate (line 747) | static public Matrix4x4d Translate(Vector3d v)
    method Scale (line 758) | static public Matrix4x4d Scale(Vector3d v)
    method Scale (line 769) | static public Matrix4x4d Scale(double s)
    method RotateX (line 780) | static public Matrix4x4d RotateX(double angle)
    method RotateY (line 794) | static public Matrix4x4d RotateY(double angle)
    method RotateZ (line 808) | static public Matrix4x4d RotateZ(double angle)
    method Rotate (line 822) | static public Matrix4x4d Rotate(Vector3d euler)
    method Perspective (line 830) | static public Matrix4x4d Perspective(double fovy, double aspect, doubl...
    method Ortho (line 842) | static public Matrix4x4d Ortho(double xRight, double xLeft, double yTo...
    method LookAt (line 857) | static public Matrix4x4d LookAt(Vector3d position, Vector3d target, Ve...

FILE: Assets/Common/LinearAlgebra/Matrix4x4f.cs
  type Matrix4x4f (line 12) | [StructLayout(LayoutKind.Sequential)]
    method Matrix4x4f (line 35) | public Matrix4x4f(float m00, float m01, float m02, float m03,
    method Matrix4x4f (line 50) | public Matrix4x4f(float v)
    method Matrix4x4f (line 61) | public Matrix4x4f(float[,] m)
    method Matrix4x4f (line 72) | public Matrix4x4f(float[] m)
    method Equals (line 528) | public override bool Equals (object obj)
    method Equals (line 540) | public bool Equals (Matrix4x4f mat)
    method EqualsWithError (line 548) | public bool EqualsWithError(Matrix4x4f m, float eps)
    method GetHashCode (line 576) | public override int GetHashCode()
    method ToString (line 589) | public override string ToString()
    method Minor (line 600) | private float Minor(int r0, int r1, int r2, int c0, int c1, int c2)
    method TryInverse (line 611) | public bool TryInverse(out Matrix4x4f mInv)
    method GetColumn (line 629) | public Vector4f GetColumn(int iCol)
    method SetColumn (line 637) | public void SetColumn(int iCol, Vector4f v)
    method FlipColumn (line 648) | public void FlipColumn(int iCol)
    method GetRow (line 659) | public Vector4f GetRow(int iRow)
    method SetRow (line 667) | public void SetRow(int iRow, Vector4f v)
    method FlipRow (line 678) | public void FlipRow(int iRow)
    method ToMatrix3x3f (line 689) | public Matrix3x3f ToMatrix3x3f()
    method TranslateRotateScale (line 703) | static public Matrix4x4f TranslateRotateScale(Vector3f t, Quaternion3f...
    method TranslateRotate (line 715) | static public Matrix4x4f TranslateRotate(Vector3f t, Quaternion3f r)
    method TranslateScale (line 726) | static public Matrix4x4f TranslateScale(Vector3f t, Vector3f s)
    method RotateScale (line 737) | static public Matrix4x4f RotateScale(Quaternion3f r, Vector3f s)
    method Translate (line 748) | static public Matrix4x4f Translate(Vector3f v)
    method Scale (line 759) | static public Matrix4x4f Scale(Vector3f v)
    method Scale (line 770) | static public Matrix4x4f Scale(float s)
    method RotateX (line 781) | static public Matrix4x4f RotateX(float angle)
    method RotateY (line 795) | static public Matrix4x4f RotateY(float angle)
    method RotateZ (line 809) | static public Matrix4x4f RotateZ(float angle)
    method Rotate (line 823) | static public Matrix4x4f Rotate(Vector3f euler)
    method Perspective (line 831) | static public Matrix4x4f Perspective(float fovy, float aspect, float z...
    method Ortho (line 843) | static public Matrix4x4f Ortho(float xRight, float xLeft, float yTop, ...
    method LookAt (line 858) | static public Matrix4x4f LookAt(Vector3f position, Vector3f target, Ve...

FILE: Assets/Common/LinearAlgebra/MatrixMxN.cs
  class MatrixMxN (line 8) | public static class MatrixMxN
    method MultiplyVector (line 11) | public static double[] MultiplyVector(double[,] matrix, double[] vector)
    method MultiplyMatrix (line 35) | public static double[] MultiplyMatrix(double[] matrix1, double[,] matr...
    method MultiplyMatrix (line 59) | public static double[,] MultiplyMatrix(double[,] matrix1, double[,] ma...
    method MultiplyScalar (line 86) | public static double[,] MultiplyScalar(double[,] matrix, double v)
    method Add (line 102) | public static double[,] Add(double[,] matrix1, double[,] matrix2)
    method Subtract (line 121) | public static double[,] Subtract(double[,] matrix1, double[,] matrix2)
    method Transpose (line 140) | public static double[,] Transpose(double[,] matrix)
    method Inverse (line 156) | public static double[,] Inverse(double[,] matrix)
    method Determinant (line 161) | public static double Determinant(double[,] matrix)
    method Cofactor (line 182) | public static double[,] Cofactor(double[,] matrix)
    method SubMatrix (line 200) | public static double[,] SubMatrix(double[,] matrix, int excluding_row,...
    method ChangeSign (line 224) | private static int ChangeSign(int i)

FILE: Assets/Common/LinearAlgebra/Quaternion3d.cs
  type Quaternion3d (line 11) | [StructLayout(LayoutKind.Sequential)]
    method Quaternion3d (line 24) | public Quaternion3d(double x, double y, double z, double w)
    method Quaternion3d (line 35) | public Quaternion3d(double[] v)
    method Equals (line 97) | public override bool Equals (object obj)
    method GetHashCode (line 109) | public override int GetHashCode()
    method ToString (line 123) | public override string ToString()
    method Quaternion3d (line 132) | public Quaternion3d(Vector3d axis, double angle)
    method Quaternion3d (line 148) | public Quaternion3d(Vector3d to, Vector3d from)
    method ToMatrix3x3d (line 213) | public Matrix3x3d ToMatrix3x3d()
    method ToMatrix4x4d (line 236) | public Matrix4x4d ToMatrix4x4d()
    method Normalize (line 260) | public void Normalize()
    method Slerp (line 272) | public static Quaternion3d Slerp(Quaternion3d from, Quaternion3d to, d...
    method FromEuler (line 315) | public static Quaternion3d FromEuler(Vector3d euler)

FILE: Assets/Common/LinearAlgebra/Quaternion3f.cs
  type Quaternion3f (line 11) | [StructLayout(LayoutKind.Sequential)]
    method Quaternion3f (line 24) | public Quaternion3f(float x, float y, float z, float w)
    method Quaternion3f (line 35) | public Quaternion3f(float[] v)
    method Equals (line 97) | public override bool Equals (object obj)
    method GetHashCode (line 109) | public override int GetHashCode()
    method ToString (line 123) | public override string ToString()
    method Quaternion3f (line 132) | public Quaternion3f(Vector3f axis, float angle)
    method Quaternion3f (line 148) | public Quaternion3f(Vector3f to, Vector3f from)
    method ToMatrix3x3f (line 213) | public Matrix3x3f ToMatrix3x3f()
    method ToMatrix4x4f (line 236) | public Matrix4x4f ToMatrix4x4f()
    method Normalize (line 260) | public void Normalize()
    method Slerp (line 272) | public static Quaternion3f Slerp(Quaternion3f from, Quaternion3f to, f...
    method FromEuler (line 314) | public static Quaternion3f FromEuler(Vector3f euler)

FILE: Assets/Common/LinearAlgebra/Vector2d.cs
  type Vector2d (line 12) | [StructLayout(LayoutKind.Sequential)]
    method Vector2d (line 58) | public Vector2d(double v)
    method Vector2d (line 67) | public Vector2d(double x, double y)
    method Equals (line 269) | public override bool Equals (object obj)
    method EqualsWithError (line 281) | public bool EqualsWithError(Vector2d v, double eps)
    method Equals (line 291) | public bool Equals(Vector2d v)
    method GetHashCode (line 299) | public override int GetHashCode()
    method ToString (line 312) | public override string ToString()
    method FromString (line 320) | static public Vector2d FromString(string s)
    method Dot (line 340) | public static double Dot(Vector2d v0, Vector2d v1)
    method Normalize (line 348) | public void Normalize()
    method Cross (line 358) | public static double Cross(Vector2d v0, Vector2d v1)
    method Distance (line 366) | public static double Distance(Vector2d v0, Vector2d v1)
    method SqrDistance (line 374) | public static double SqrDistance(Vector2d v0, Vector2d v1)
    method Angle180 (line 384) | public static double Angle180(Vector2d a, Vector2d b)
    method AngleCCW (line 397) | public static double AngleCCW(Vector2d a, Vector2d b)
    method Min (line 410) | public void Min(double s)
    method Min (line 419) | public void Min(Vector2d v)
    method Max (line 428) | public void Max(double s)
    method Max (line 437) | public void Max(Vector2d v)
    method Abs (line 446) | public void Abs()
    method Clamp (line 455) | public void Clamp(double min, double max)
    method Clamp (line 464) | public void Clamp(Vector2d min, Vector2d max)
    method Lerp (line 473) | public static Vector2d Lerp(Vector2d from, Vector2d to, double t)
    method Slerp (line 491) | public static Vector2d Slerp(Vector2d from, Vector2d to, double t)

FILE: Assets/Common/LinearAlgebra/Vector2f.cs
  type Vector2f (line 12) | [StructLayout(LayoutKind.Sequential)]
    method Vector2f (line 58) | public Vector2f(float v)
    method Vector2f (line 67) | public Vector2f(float x, float y)
    method Equals (line 269) | public override bool Equals (object obj)
    method EqualsWithError (line 281) | public bool EqualsWithError(Vector2f v, float eps)
    method Equals (line 291) | public bool Equals(Vector2f v)
    method GetHashCode (line 299) | public override int GetHashCode()
    method ToString (line 312) | public override string ToString()
    method FromString (line 320) | static public Vector2f FromString(string s)
    method Dot (line 340) | public static float Dot(Vector2f v0, Vector2f v1)
    method Normalize (line 348) | public void Normalize()
    method Cross (line 358) | public static float Cross(Vector2f v0, Vector2f v1)
    method Distance (line 366) | public static float Distance(Vector2f v0, Vector2f v1)
    method SqrDistance (line 374) | public static float SqrDistance(Vector2f v0, Vector2f v1)
    method Angle180 (line 384) | public static float Angle180(Vector2f a, Vector2f b)
    method Angle360 (line 400) | public static float Angle360(Vector2f a, Vector2f b)
    method Min (line 414) | public void Min(float s)
    method Min (line 423) | public void Min(Vector2f v)
    method Max (line 432) | public void Max(float s)
    method Max (line 441) | public void Max(Vector2f v)
    method Abs (line 450) | public void Abs()
    method Clamp (line 459) | public void Clamp(float min, float max)
    method Clamp (line 468) | public void Clamp(Vector2f min, Vector2f max)
    method Lerp (line 477) | public static Vector2f Lerp(Vector2f from, Vector2f to, float t)
    method Slerp (line 495) | public static Vector2f Slerp(Vector2f from, Vector2f to, float t)

FILE: Assets/Common/LinearAlgebra/Vector2i.cs
  type Vector2i (line 10) | [StructLayout(LayoutKind.Sequential)]
    method Vector2i (line 53) | public Vector2i(int v)
    method Vector2i (line 59) | public Vector2i(int x, int y)
    method Equals (line 227) | public override bool Equals (object obj)
    method Equals (line 239) | public bool Equals(Vector2i v)
    method GetHashCode (line 248) | public override int GetHashCode()
    method ToString (line 264) | public override string ToString()
    method FromString (line 272) | static public Vector2i FromString(string s)
    method Dot (line 293) | public static int Dot(Vector2i v0, Vector2i v1)
    method Cross (line 301) | public static int Cross(Vector2i v0, Vector2i v1)
    method Distance (line 309) | public static double Distance(Vector2i v0, Vector2i v1)
    method SqrDistance (line 317) | public static double SqrDistance(Vector2i v0, Vector2i v1)
    method Min (line 327) | public void Min(int s)
    method Min (line 336) | public void Min(Vector2i v)
    method Max (line 345) | public void Max(int s)
    method Max (line 354) | public void Max(Vector2i v)
    method Abs (line 362) | public void Abs()
    method Clamp (line 371) | public void Clamp(int min, int max)
    method Clamp (line 380) | public void Clamp(Vector2i min, Vector2i max)

FILE: Assets/Common/LinearAlgebra/Vector3d.cs
  type Vector3d (line 14) | [StructLayout(LayoutKind.Sequential)]
    method Vector3d (line 89) | public Vector3d(double v)
    method Vector3d (line 99) | public Vector3d(double x, double y, double z)
    method Vector3d (line 109) | public Vector3d(Vector2d v, double z)
    method Equals (line 292) | public override bool Equals (object obj)
    method EqualsWithError (line 304) | public bool EqualsWithError(Vector3d v, double eps)
    method Equals (line 315) | public bool Equals(Vector3d v)
    method GetHashCode (line 323) | public override int GetHashCode()
    method ToString (line 336) | public override string ToString()
    method FromString (line 344) | static public Vector3d FromString(string s)
    method Dot (line 365) | public static double Dot(Vector3d v0, Vector3d v1)
    method Normalize (line 373) | public void Normalize()
    method Cross (line 384) | public Vector3d Cross(Vector3d v)
    method Cross (line 392) | public static Vector3d Cross(Vector3d v0, Vector3d v1)
    method Distance (line 400) | public static double Distance(Vector3d v0, Vector3d v1)
    method SqrDistance (line 408) | public static double SqrDistance(Vector3d v0, Vector3d v1)
    method Min (line 419) | public void Min(double s)
    method Min (line 429) | public void Min(Vector3d v)
    method Max (line 439) | public void Max(double s)
    method Max (line 449) | public void Max(Vector3d v)
    method Abs (line 459) | public void Abs()
    method Clamp (line 469) | public void Clamp(double min, double max)
    method Clamp (line 479) | public void Clamp(Vector3d min, Vector3d max)
    method Lerp (line 489) | public static Vector3d Lerp(Vector3d from, Vector3d to, double t)
    method Slerp (line 508) | public static Vector3d Slerp(Vector3d from, Vector3d to, double t)

FILE: Assets/Common/LinearAlgebra/Vector3f.cs
  type Vector3f (line 14) | [StructLayout(LayoutKind.Sequential)]
    method Vector3f (line 89) | public Vector3f(float v)
    method Vector3f (line 99) | public Vector3f(float x, float y, float z)
    method Vector3f (line 109) | public Vector3f(Vector2f v, float z)
    method Equals (line 292) | public override bool Equals (object obj)
    method EqualsWithError (line 304) | public bool EqualsWithError(Vector3f v, float eps)
    method Equals (line 315) | public bool Equals(Vector3f v)
    method GetHashCode (line 323) | public override int GetHashCode()
    method ToString (line 336) | public override string ToString()
    method FromString (line 344) | static public Vector3f FromString(string s)
    method Dot (line 365) | public static float Dot(Vector3f v0, Vector3f v1)
    method Normalize (line 373) | public void Normalize()
    method Cross (line 384) | public Vector3f Cross(Vector3f v)
    method Cross (line 392) | public static Vector3f Cross(Vector3f v0, Vector3f v1)
    method Distance (line 400) | public static float Distance(Vector3f v0, Vector3f v1)
    method SqrDistance (line 408) | public static float SqrDistance(Vector3f v0, Vector3f v1)
    method Min (line 419) | public void Min(float s)
    method Min (line 429) | public void Min(Vector3f v)
    method Max (line 439) | public void Max(float s)
    method Max (line 449) | public void Max(Vector3f v)
    method Abs (line 459) | public void Abs()
    method Clamp (line 469) | public void Clamp(float min, float max)
    method Clamp (line 479) | public void Clamp(Vector3f min, Vector3f max)
    method Lerp (line 489) | public static Vector3f Lerp(Vector3f from, Vector3f to, float t)
    method Slerp (line 508) | public static Vector3f Slerp(Vector3f from, Vector3f to, float t)

FILE: Assets/Common/LinearAlgebra/Vector3i.cs
  type Vector3i (line 10) | [StructLayout(LayoutKind.Sequential)]
    method Vector3i (line 50) | public Vector3i(int v)
    method Vector3i (line 57) | public Vector3i(int x, int y, int z)
    method Equals (line 228) | public override bool Equals (object obj)
    method Equals (line 240) | public bool Equals(Vector3i v)
    method GetHashCode (line 248) | public override int GetHashCode()
    method ToString (line 265) | public override string ToString()
    method FromString (line 273) | static public Vector3i FromString(string s)
    method Dot (line 293) | public static int Dot(Vector3i v0, Vector3i v1)
    method Cross (line 301) | public static Vector3i Cross(Vector3i v0, Vector3i v1)
    method Distance (line 309) | public static double Distance(Vector3i v0, Vector3i v1)
    method SqrDistance (line 317) | public static double SqrDistance(Vector3i v0, Vector3i v1)
    method Min (line 328) | public void Min(int s)
    method Min (line 338) | public void Min(Vector3i v)
    method Max (line 348) | public void Max(int s)
    method Max (line 358) | public void Max(Vector3i v)
    method Abs (line 368) | public void Abs()
    method Clamp (line 378) | public void Clamp(int min, int max)
    method Clamp (line 388) | public void Clamp(Vector3i min, Vector3i max)

FILE: Assets/Common/LinearAlgebra/Vector4d.cs
  type Vector4d (line 13) | [StructLayout(LayoutKind.Sequential)]
    method Vector4d (line 86) | public Vector4d(double v)
    method Vector4d (line 97) | public Vector4d(double x, double y, double z, double w)
    method Vector4d (line 108) | public Vector4d(Vector2d v, double z, double w)
    method Vector4d (line 119) | public Vector4d(Vector3d v, double w)
    method Equals (line 305) | public override bool Equals (object obj)
    method EqualsWithError (line 317) | public bool EqualsWithError(Vector4d v, double eps)
    method Equals (line 329) | public bool Equals(Vector4d v)
    method GetHashCode (line 337) | public override int GetHashCode()
    method ToString (line 351) | public override string ToString() {
    method FromString (line 358) | static public Vector4d FromString(string s)
    method Dot (line 379) | public static double Dot(Vector4d v0, Vector4d v1)
    method Distance (line 387) | public static double Distance(Vector4d v0, Vector4d v1)
    method SqrDistance (line 395) | public static double SqrDistance(Vector4d v0, Vector4d v1)
    method Normalize (line 407) | public void Normalize()
    method Min (line 419) | public void Min(double s)
    method Min (line 430) | public void Min(Vector4d v)
    method Max (line 441) | public void Max(double s)
    method Max (line 452) | public void Max(Vector4d v)
    method Abs (line 463) | public void Abs()
    method Clamp (line 474) | public void Clamp(double min, double max)
    method Clamp (line 485) | public void Clamp(Vector4d min, Vector4d max)
    method Lerp (line 496) | public static Vector4d Lerp(Vector4d from, Vector4d to, double t)

FILE: Assets/Common/LinearAlgebra/Vector4f.cs
  type Vector4f (line 13) | [StructLayout(LayoutKind.Sequential)]
    method Vector4f (line 86) | public Vector4f(float v)
    method Vector4f (line 97) | public Vector4f(float x, float y, float z, float w)
    method Vector4f (line 108) | public Vector4f(Vector2f v, float z, float w)
    method Vector4f (line 119) | public Vector4f(Vector3f v, float w)
    method Equals (line 305) | public override bool Equals (object obj)
    method EqualsWithError (line 317) | public bool EqualsWithError(Vector4f v, float eps)
    method Equals (line 329) | public bool Equals(Vector4f v)
    method GetHashCode (line 337) | public override int GetHashCode()
    method ToString (line 351) | public override string ToString()
    method FromString (line 359) | static public Vector4f FromString(string s)
    method Dot (line 380) | public static float Dot(Vector4f v0, Vector4f v1)
    method Distance (line 388) | public static float Distance(Vector4f v0, Vector4f v1)
    method SqrDistance (line 396) | public static float SqrDistance(Vector4f v0, Vector4f v1)
    method Normalize (line 408) | public void Normalize()
    method Min (line 420) | public void Min(float s)
    method Min (line 431) | public void Min(Vector4f v)
    method Max (line 442) | public void Max(float s)
    method Max (line 453) | public void Max(Vector4f v)
    method Abs (line 464) | public void Abs()
    method Clamp (line 475) | public void Clamp(float min, float max)
    method Clamp (line 486) | public void Clamp(Vector4f min, Vector4f max)
    method Lerp (line 497) | public static Vector4f Lerp(Vector4f from, Vector4f to, float t)

FILE: Assets/Common/LinearAlgebra/Vector4i.cs
  type Vector4i (line 10) | [StructLayout(LayoutKind.Sequential)]
    method Vector4i (line 55) | public Vector4i(int v)
    method Vector4i (line 63) | public Vector4i(int x, int y, int z, int w)
    method Equals (line 237) | public override bool Equals (object obj)
    method Equals (line 249) | public bool Equals(Vector4i v)
    method GetHashCode (line 257) | public override int GetHashCode()
    method ToString (line 275) | public override string ToString()
    method FromString (line 283) | static public Vector4i FromString(string s)
    method Dot (line 305) | public static int Dot(Vector4i v0, Vector4i v1)
    method Distance (line 313) | public static double Distance(Vector4i v0, Vector4i v1)
    method SqrDistance (line 321) | public static double SqrDistance(Vector4i v0, Vector4i v1)
    method Min (line 333) | public void Min(int s)
    method Min (line 344) | public void Min(Vector4i v)
    method Max (line 355) | public void Max(int s)
    method Max (line 366) | public void Max(Vector4i v)
    method Abs (line 377) | public void Abs()
    method Clamp (line 388) | public void Clamp(int min, int max)
    method Clamp (line 399) | public void Clamp(Vector4i min, Vector4i max)

FILE: Assets/Common/Mathematics/DMath.cs
  class DMath (line 5) | public class DMath
    method SafeAcos (line 16) | public static double SafeAcos(double r)
    method SafeAsin (line 21) | public static double SafeAsin(double r)
    method SafeSqrt (line 26) | public static double SafeSqrt(double v)
    method SafeInvSqrt (line 32) | public static double SafeInvSqrt(double n, double d)
    method SafeInv (line 40) | public static double SafeInv(double v)
    method SafeDiv (line 46) | public static double SafeDiv(double n, double d)
    method IsZero (line 52) | public static bool IsZero(double v)
    method IsFinite (line 57) | public static bool IsFinite(double f)
    method Clamp (line 62) | public static double Clamp(double v, double min, double max)
    method Clamp01 (line 69) | public static double Clamp01(double v)
    method SmoothStep (line 76) | public static double SmoothStep(double edge0, double edge1, double x)
    method Frac (line 82) | public static double Frac(double x)
    method Lerp (line 87) | public static double Lerp(double v0, double v1, double a)

FILE: Assets/Common/Mathematics/FMath.cs
  class FMath (line 5) | public class FMath
    method SafeAcos (line 15) | public static float SafeAcos(float r)
    method SafeAsin (line 20) | public static float SafeAsin(float r)
    method SafeSqrt (line 25) | public static float SafeSqrt(float v)
    method SafeInvSqrt (line 31) | public static float SafeInvSqrt(float n, float d)
    method SafeInv (line 39) | public static float SafeInv(float v)
    method SafeDiv (line 45) | public static float SafeDiv(float n, float d)
    method IsZero (line 51) | public static bool IsZero(float v)
    method IsFinite (line 56) | public static bool IsFinite(float f)
    method Clamp (line 61) | public static float Clamp(float v, float min, float max)
    method Clamp01 (line 68) | public static float Clamp01(float v)
    method SmoothStep (line 75) | public static float SmoothStep(float edge0, float edge1, float x)
    method Frac (line 81) | public static float Frac(float x)
    method Lerp (line 86) | public static float Lerp(float v0, float v1, float a)

FILE: Assets/Common/Mathematics/IMath.cs
  class IMath (line 5) | public class IMath
    method Clamp (line 8) | public static int Clamp(int v, int min, int max)
    method IsPow2 (line 15) | public static bool IsPow2(int num)
    method NearestPow2 (line 24) | public static int NearestPow2(int num)
    method LowerPow2 (line 38) | public static int LowerPow2(int num)

FILE: Assets/FEM2D/Scripts/CreateCantileverBeam.cs
  class CreateCantileverBeam (line 10) | public static class CreateCantileverBeam
    method Create (line 13) | public static FEMScene Create(Vector2f origin, float scale, int numPoi...

FILE: Assets/FEM2D/Scripts/CreateFromImage.cs
  class CreateFromImage (line 10) | public static class CreateFromImage
    method ToWorldPos (line 18) | private static Vector2f ToWorldPos(Vector2f p)
    method Create (line 26) | public static FEMScene Create(Texture2D img)
    method Neighbours (line 161) | private static int Neighbours(Texture2D img, int cx, int cy, int margin)
    method EdgeDetect (line 185) | private static bool EdgeDetect(Texture2D img, int x, int y)

FILE: Assets/FEM2D/Scripts/CreateRandomConvex.cs
  class CreateRandomConvex (line 10) | public static class CreateRandomConvex
    method Create (line 13) | public static FEMScene Create(Vector2f origin, float scale, int numPoi...

FILE: Assets/FEM2D/Scripts/CreateTorus.cs
  class CreateTorus (line 10) | public static class CreateTorus
    method Create (line 13) | public static FEMScene Create(Vector2f origin, float inner, float oute...

FILE: Assets/FEM2D/Scripts/DelaunayTriangulation.cs
  class DelaunayTriangle (line 11) | public class DelaunayTriangle
    method DelaunayTriangle (line 19) | public DelaunayTriangle(int i, int j, int k)
    method CalculateCircumcircle (line 26) | public void CalculateCircumcircle(IList<Vector2f> vertices)
    method MakeCCW (line 52) | public void MakeCCW(IList<Vector2f> vertices)
    method TriArea (line 62) | public float TriArea(IList<Vector2f> vertices)
  class Edge (line 97) | public class Edge
    method Edge (line 101) | public Edge(int i, int j)
  class DelaunayTriangulation (line 108) | public class DelaunayTriangulation
    method DelaunayTriangulation (line 115) | public DelaunayTriangulation()
    method Triangulate (line 122) | public void Triangulate(IList<Vector2f> points)
    method AddBoundingTriangle (line 159) | private void AddBoundingTriangle(IList<Vector2f> points)
    method ContainsEdge (line 195) | private int ContainsEdge(List<Edge> edges, Edge e)
    method Insert (line 207) | private void Insert(Vector2f p)

FILE: Assets/FEM2D/Scripts/FEMDemo.cs
  type FEM_SCENE (line 10) | public enum FEM_SCENE { BEAM, RANDOM_CONVEX, TORUS, ARMADILLO, BUNNY, DO...
  class FEMDemo (line 12) | public class FEMDemo : MonoBehaviour
    method Start (line 48) | void Start()
    method FixedUpdate (line 104) | void FixedUpdate()
    method FindClosestParticle (line 131) | int FindClosestParticle()
    method MoveByMouseDrag (line 149) | void MoveByMouseDrag(float dt)
    method OnPostRender (line 165) | private void OnPostRender()
    method DrawPoint (line 192) | private void DrawPoint(Vector2f p, float s)
    method DrawPoint (line 200) | private void DrawPoint(Vector2 p, float s)
    method DrawMouseLine (line 208) | private void DrawMouseLine()
    method DrawScenePlanes (line 226) | private void DrawScenePlanes()
    method DrawFracturePlanes (line 248) | private void DrawFracturePlanes()
    method DrawTexturedTriangles (line 270) | private void DrawTexturedTriangles()
    method DrawLineTriangles (line 313) | private void DrawLineTriangles()
    method DrawMouseVert (line 344) | private void DrawMouseVert()
    method DrawModelVerts (line 358) | private void DrawModelVerts()

FILE: Assets/FEM2D/Scripts/FEMElement.cs
  class FEMElement (line 9) | public class FEMElement
    method FEMElement (line 11) | public FEMElement(Vector2f[] x)

FILE: Assets/FEM2D/Scripts/FEMFractureEvent.cs
  type FEMFractureEvent (line 9) | public struct FEMFractureEvent

FILE: Assets/FEM2D/Scripts/FEMParticle.cs
  class FEMParticle (line 10) | public class FEMParticle
    method FEMParticle (line 22) | public FEMParticle(Vector2f pos, float im)
    method FEMParticle (line 29) | public FEMParticle(Vector2f pos, Vector2f uv, float im)
    method Copy (line 37) | public FEMParticle Copy()

FILE: Assets/FEM2D/Scripts/FEMScene.cs
  class FEMScene (line 11) | public class FEMScene
    method FEMScene (line 46) | public FEMScene()
    method CreateElements (line 56) | public void CreateElements()
    method Update (line 77) | public void Update(float dt)
    method UpdateForces (line 97) | private void UpdateForces(float dt, bool performFracture)
    method IntegrateForces (line 236) | private void IntegrateForces(float dt)
    method CollidePlanes (line 247) | private void CollidePlanes()
    method GetVertex (line 280) | private int GetVertex(Triangle tri, int i)
    method FrobeniusNorm (line 292) | float FrobeniusNorm(Matrix2x2f m)
    method CalcDeformation (line 306) | private Matrix2x2f CalcDeformation(Vector2f[] x, Matrix2x2f invM)
    method CalcGreenStrainTensor (line 323) | private Matrix2x2f CalcGreenStrainTensor(Matrix2x2f f)
    method CalcGreenStrainTensorDt (line 332) | private Matrix2x2f CalcGreenStrainTensorDt(Matrix2x2f f, Matrix2x2f dfdt)
    method CalcCauchyStrainTensor (line 341) | private Matrix2x2f CalcCauchyStrainTensor(Matrix2x2f f)
    method CalcCauchyStrainTensorDt (line 350) | private Matrix2x2f CalcCauchyStrainTensorDt(Matrix2x2f dfdt)
    method CalcStressTensor (line 359) | private Matrix2x2f CalcStressTensor(Matrix2x2f e, float lambda, float mu)

FILE: Assets/FEM2D/Scripts/Mesher.cs
  class Mesher (line 10) | public class Mesher
    method TriangulateDelaunay (line 16) | public static void TriangulateDelaunay(List<Vector2f> points, out List...
    method CreateTorus (line 50) | public static void CreateTorus(List<Vector2f> points, List<int> indice...
    method TriangulateVariational (line 93) | public static void TriangulateVariational(List<Vector2f> inPoints, Lis...

FILE: Assets/FEM2D/Scripts/Triangle.cs
  class Triangle (line 9) | public class Triangle
    method Triangle (line 13) | public Triangle(int i, int j, int k)
Condensed preview — 116 files, each showing path, character count, and a content snippet. Download the .json file or copy for the full structured content (473K chars).
[
  {
    "path": ".gitignore",
    "chars": 313,
    "preview": "################################################################################\n# This .gitignore file was automatical"
  },
  {
    "path": "Assets/Common/Decomposition/Decomposition2x2d.cs",
    "chars": 1993,
    "preview": "using System;\r\nusing System.Collections.Generic;\r\n\r\nusing Common.Core.LinearAlgebra;\r\n\r\nnamespace Common.Mathematics.De"
  },
  {
    "path": "Assets/Common/Decomposition/Decomposition2x2d.cs.meta",
    "chars": 285,
    "preview": "fileFormatVersion: 2\nguid: 60689437f1f73d04da8380919053e6e8\ntimeCreated: 1514536270\nlicenseType: Free\nMonoImporter:\n  ex"
  },
  {
    "path": "Assets/Common/Decomposition/Decomposition2x2f.cs",
    "chars": 1994,
    "preview": "using System;\r\nusing System.Collections.Generic;\r\n\r\nusing Common.Core.LinearAlgebra;\r\n\r\nnamespace Common.Mathematics.De"
  },
  {
    "path": "Assets/Common/Decomposition/Decomposition2x2f.cs.meta",
    "chars": 285,
    "preview": "fileFormatVersion: 2\nguid: 677436b12b96e754eb23bb58733959f9\ntimeCreated: 1514536270\nlicenseType: Free\nMonoImporter:\n  ex"
  },
  {
    "path": "Assets/Common/Decomposition/Decomposition3x3d.cs",
    "chars": 14539,
    "preview": "using System;\r\n\r\nusing Common.Core.LinearAlgebra;\r\n\r\nnamespace Common.Mathematics.Decomposition\r\n{\r\n\r\n    public static"
  },
  {
    "path": "Assets/Common/Decomposition/Decomposition3x3d.cs.meta",
    "chars": 285,
    "preview": "fileFormatVersion: 2\nguid: 4c6eedd17e5c16345a731cb65b62ab3c\ntimeCreated: 1514536270\nlicenseType: Free\nMonoImporter:\n  ex"
  },
  {
    "path": "Assets/Common/Decomposition/Decomposition3x3f.cs",
    "chars": 12822,
    "preview": "using System;\r\n\r\nusing Common.Core.LinearAlgebra;\r\n\r\nnamespace Common.Mathematics.Decomposition\r\n{\r\n\r\n    public static "
  },
  {
    "path": "Assets/Common/Decomposition/Decomposition3x3f.cs.meta",
    "chars": 285,
    "preview": "fileFormatVersion: 2\nguid: c51f4ad5b0f26454b81446d12138e40d\ntimeCreated: 1514536270\nlicenseType: Free\nMonoImporter:\n  ex"
  },
  {
    "path": "Assets/Common/Decomposition.meta",
    "chars": 214,
    "preview": "fileFormatVersion: 2\nguid: ca3a86e2d1148ce4a9d75690faa7ade4\nfolderAsset: yes\ntimeCreated: 1514536270\nlicenseType: Free\nD"
  },
  {
    "path": "Assets/Common/LinearAlgebra/Matrix2x2d.cs",
    "chars": 11439,
    "preview": "using System;\r\nusing System.Collections;\r\nusing System.Runtime.InteropServices;\r\n\r\nusing Common.Core.Mathematics;\r\n\r\nnam"
  },
  {
    "path": "Assets/Common/LinearAlgebra/Matrix2x2d.cs.meta",
    "chars": 285,
    "preview": "fileFormatVersion: 2\nguid: 84b9e005a3c7e82429bbb49ae4ad0119\ntimeCreated: 1514536270\nlicenseType: Free\nMonoImporter:\n  ex"
  },
  {
    "path": "Assets/Common/LinearAlgebra/Matrix2x2f.cs",
    "chars": 11401,
    "preview": "using System;\r\nusing System.Collections;\r\nusing System.Runtime.InteropServices;\r\n\r\nusing Common.Core.Mathematics;\r\n\r\nnam"
  },
  {
    "path": "Assets/Common/LinearAlgebra/Matrix2x2f.cs.meta",
    "chars": 285,
    "preview": "fileFormatVersion: 2\nguid: 5552436bd5f193c4c8a224e34dc6e321\ntimeCreated: 1514536270\nlicenseType: Free\nMonoImporter:\n  ex"
  },
  {
    "path": "Assets/Common/LinearAlgebra/Matrix3x3d.cs",
    "chars": 19009,
    "preview": "using System;\r\nusing System.Collections;\r\nusing System.Runtime.InteropServices;\r\n\r\nusing Common.Core.Mathematics;\r\n\r\nnam"
  },
  {
    "path": "Assets/Common/LinearAlgebra/Matrix3x3d.cs.meta",
    "chars": 285,
    "preview": "fileFormatVersion: 2\nguid: e1ff789641c35454ebfd3d438dcc6189\ntimeCreated: 1514536271\nlicenseType: Free\nMonoImporter:\n  ex"
  },
  {
    "path": "Assets/Common/LinearAlgebra/Matrix3x3f.cs",
    "chars": 18414,
    "preview": "using System;\r\nusing System.Collections;\r\nusing System.Runtime.InteropServices;\r\n\r\nusing Common.Core.Mathematics;\r\n\r\nnam"
  },
  {
    "path": "Assets/Common/LinearAlgebra/Matrix3x3f.cs.meta",
    "chars": 285,
    "preview": "fileFormatVersion: 2\nguid: 0d592915ed7730b46b7e07319de6f32c\ntimeCreated: 1514536270\nlicenseType: Free\nMonoImporter:\n  ex"
  },
  {
    "path": "Assets/Common/LinearAlgebra/Matrix4x4d.cs",
    "chars": 28662,
    "preview": "using System;\r\nusing System.Collections;\r\nusing System.Runtime.InteropServices;\r\n\r\nusing Common.Core.Mathematics;\r\n\r\nnam"
  },
  {
    "path": "Assets/Common/LinearAlgebra/Matrix4x4d.cs.meta",
    "chars": 285,
    "preview": "fileFormatVersion: 2\nguid: deeb67b15435ece419f1249c52ba4c99\ntimeCreated: 1514536271\nlicenseType: Free\nMonoImporter:\n  ex"
  },
  {
    "path": "Assets/Common/LinearAlgebra/Matrix4x4f.cs",
    "chars": 28695,
    "preview": "using System;\r\nusing System.Collections;\r\nusing System.Runtime.InteropServices;\r\n\r\nusing Common.Core.Mathematics;\r\n\r\nnam"
  },
  {
    "path": "Assets/Common/LinearAlgebra/Matrix4x4f.cs.meta",
    "chars": 285,
    "preview": "fileFormatVersion: 2\nguid: b23ff530d822b7145adbcab5a4583011\ntimeCreated: 1514536270\nlicenseType: Free\nMonoImporter:\n  ex"
  },
  {
    "path": "Assets/Common/LinearAlgebra/MatrixMxN.cs",
    "chars": 6890,
    "preview": "using System;\r\nusing System.Collections.Generic;\r\n\r\nusing Common.Core.Mathematics;\r\n\r\nnamespace Common.Core.LinearAlgeb"
  },
  {
    "path": "Assets/Common/LinearAlgebra/MatrixMxN.cs.meta",
    "chars": 285,
    "preview": "fileFormatVersion: 2\nguid: d64ab62afd178ca4f9b734695ee8f4e6\ntimeCreated: 1514536270\nlicenseType: Free\nMonoImporter:\n  ex"
  },
  {
    "path": "Assets/Common/LinearAlgebra/Quaternion3d.cs",
    "chars": 9736,
    "preview": "using System;\r\nusing System.Runtime.InteropServices;\r\n\r\nusing Common.Core.Mathematics;\r\n\r\nnamespace Common.Core.LinearAl"
  },
  {
    "path": "Assets/Common/LinearAlgebra/Quaternion3d.cs.meta",
    "chars": 285,
    "preview": "fileFormatVersion: 2\nguid: c2b4193eee97e4649ad3948f8e99a317\ntimeCreated: 1514536270\nlicenseType: Free\nMonoImporter:\n  ex"
  },
  {
    "path": "Assets/Common/LinearAlgebra/Quaternion3f.cs",
    "chars": 10851,
    "preview": "using System;\r\nusing System.Runtime.InteropServices;\r\n\r\nusing Common.Core.Mathematics;\r\n\r\nnamespace Common.Core.LinearAl"
  },
  {
    "path": "Assets/Common/LinearAlgebra/Quaternion3f.cs.meta",
    "chars": 285,
    "preview": "fileFormatVersion: 2\nguid: da6fc536acb153944a010e07ae652bf9\ntimeCreated: 1514536271\nlicenseType: Free\nMonoImporter:\n  ex"
  },
  {
    "path": "Assets/Common/LinearAlgebra/Vector2d.cs",
    "chars": 13520,
    "preview": "using System;\r\nusing System.Collections;\r\nusing System.Runtime.InteropServices;\r\n\r\nusing Common.Core.Mathematics;\n\nnames"
  },
  {
    "path": "Assets/Common/LinearAlgebra/Vector2d.cs.meta",
    "chars": 285,
    "preview": "fileFormatVersion: 2\nguid: c1b7dd742e9f9aa49957980a1f94d794\ntimeCreated: 1514536270\nlicenseType: Free\nMonoImporter:\n  ex"
  },
  {
    "path": "Assets/Common/LinearAlgebra/Vector2f.cs",
    "chars": 13814,
    "preview": "using System;\r\nusing System.Collections;\r\nusing System.Runtime.InteropServices;\r\n\r\nusing Common.Core.Mathematics;\n\nnames"
  },
  {
    "path": "Assets/Common/LinearAlgebra/Vector2f.cs.meta",
    "chars": 285,
    "preview": "fileFormatVersion: 2\nguid: f2c52c29076b7bb40a45c08b61f46fd4\ntimeCreated: 1514536271\nlicenseType: Free\nMonoImporter:\n  ex"
  },
  {
    "path": "Assets/Common/LinearAlgebra/Vector2i.cs",
    "chars": 9928,
    "preview": "using System;\r\nusing System.Collections;\r\nusing System.Runtime.InteropServices;\r\n\r\nusing Common.Core.Mathematics;\r\n\r\nnam"
  },
  {
    "path": "Assets/Common/LinearAlgebra/Vector2i.cs.meta",
    "chars": 285,
    "preview": "fileFormatVersion: 2\nguid: fcce9ee7e2939b748bb7812d444e1375\ntimeCreated: 1514536271\nlicenseType: Free\nMonoImporter:\n  ex"
  },
  {
    "path": "Assets/Common/LinearAlgebra/Vector3d.cs",
    "chars": 14345,
    "preview": "using System;\r\nusing System.Collections;\r\nusing System.Collections.Generic;\r\nusing System.Runtime.InteropServices;\r\n\r\nus"
  },
  {
    "path": "Assets/Common/LinearAlgebra/Vector3d.cs.meta",
    "chars": 285,
    "preview": "fileFormatVersion: 2\nguid: b9c045103d2bd44499952cd87cbdca3d\ntimeCreated: 1514536270\nlicenseType: Free\nMonoImporter:\n  ex"
  },
  {
    "path": "Assets/Common/LinearAlgebra/Vector3f.cs",
    "chars": 14870,
    "preview": "using System;\r\nusing System.Collections;\r\nusing System.Collections.Generic;\r\nusing System.Runtime.InteropServices;\r\n\r\nus"
  },
  {
    "path": "Assets/Common/LinearAlgebra/Vector3f.cs.meta",
    "chars": 285,
    "preview": "fileFormatVersion: 2\nguid: 094df8240bc2a7c4db01c45a93d719d3\ntimeCreated: 1514536270\nlicenseType: Free\nMonoImporter:\n  ex"
  },
  {
    "path": "Assets/Common/LinearAlgebra/Vector3i.cs",
    "chars": 10685,
    "preview": "using System;\r\nusing System.Collections;\r\nusing System.Runtime.InteropServices;\r\n\r\nusing Common.Core.Mathematics;\r\n\r\nnam"
  },
  {
    "path": "Assets/Common/LinearAlgebra/Vector3i.cs.meta",
    "chars": 285,
    "preview": "fileFormatVersion: 2\nguid: c429b2b651bebc94387a8eadd602aaea\ntimeCreated: 1514536270\nlicenseType: Free\nMonoImporter:\n  ex"
  },
  {
    "path": "Assets/Common/LinearAlgebra/Vector4d.cs",
    "chars": 13951,
    "preview": "using System;\r\nusing System.Collections;\r\nusing System.Runtime.InteropServices;\r\n\r\nusing Common.Core.Mathematics;\n\nnames"
  },
  {
    "path": "Assets/Common/LinearAlgebra/Vector4d.cs.meta",
    "chars": 285,
    "preview": "fileFormatVersion: 2\nguid: 2766e509106656041a199c994b986a25\ntimeCreated: 1514536270\nlicenseType: Free\nMonoImporter:\n  ex"
  },
  {
    "path": "Assets/Common/LinearAlgebra/Vector4f.cs",
    "chars": 14186,
    "preview": "using System;\r\nusing System.Collections;\r\nusing System.Runtime.InteropServices;\r\n\r\nusing Common.Core.Mathematics;\n\nnames"
  },
  {
    "path": "Assets/Common/LinearAlgebra/Vector4f.cs.meta",
    "chars": 285,
    "preview": "fileFormatVersion: 2\nguid: 8ea49a7834165304c8ca5b1bc42aaf48\ntimeCreated: 1514536270\nlicenseType: Free\nMonoImporter:\n  ex"
  },
  {
    "path": "Assets/Common/LinearAlgebra/Vector4i.cs",
    "chars": 11305,
    "preview": "using System;\r\nusing System.Collections;\r\nusing System.Runtime.InteropServices;\r\n\r\nusing Common.Core.Mathematics;\r\n\r\nnam"
  },
  {
    "path": "Assets/Common/LinearAlgebra/Vector4i.cs.meta",
    "chars": 285,
    "preview": "fileFormatVersion: 2\nguid: 76636d8a8f9545a43a7ca5a30de4b00e\ntimeCreated: 1514536270\nlicenseType: Free\nMonoImporter:\n  ex"
  },
  {
    "path": "Assets/Common/LinearAlgebra.meta",
    "chars": 214,
    "preview": "fileFormatVersion: 2\nguid: dbcf441fe7fb93143a9acab04c44f587\nfolderAsset: yes\ntimeCreated: 1514536270\nlicenseType: Free\nD"
  },
  {
    "path": "Assets/Common/Mathematics/DMath.cs",
    "chars": 2379,
    "preview": "using System;\r\n\r\nnamespace Common.Core.Mathematics\r\n{\r\n    public class DMath\r\n    {\r\n\r\n        public static readonly d"
  },
  {
    "path": "Assets/Common/Mathematics/DMath.cs.meta",
    "chars": 285,
    "preview": "fileFormatVersion: 2\nguid: e9811506d7286624cbaaa86bf5ea2ac2\ntimeCreated: 1514536310\nlicenseType: Free\nMonoImporter:\n  ex"
  },
  {
    "path": "Assets/Common/Mathematics/FMath.cs",
    "chars": 2405,
    "preview": "using System;\r\n\r\nnamespace Common.Core.Mathematics\r\n{\r\n    public class FMath\r\n    {\r\n        public static readonly flo"
  },
  {
    "path": "Assets/Common/Mathematics/FMath.cs.meta",
    "chars": 285,
    "preview": "fileFormatVersion: 2\nguid: 20b1889a7c1251b4b8ff543a0ebcb6d0\ntimeCreated: 1514536310\nlicenseType: Free\nMonoImporter:\n  ex"
  },
  {
    "path": "Assets/Common/Mathematics/IMath.cs",
    "chars": 893,
    "preview": "using System;\n\nnamespace Common.Core.Mathematics\n{\n\tpublic class IMath \n\t{\r\n\r\n        public static int Clamp(int v, int"
  },
  {
    "path": "Assets/Common/Mathematics/IMath.cs.meta",
    "chars": 285,
    "preview": "fileFormatVersion: 2\nguid: fd9b410d6fb0aeb4695a51db5bb1eaea\ntimeCreated: 1514536310\nlicenseType: Free\nMonoImporter:\n  ex"
  },
  {
    "path": "Assets/Common/Mathematics.meta",
    "chars": 214,
    "preview": "fileFormatVersion: 2\nguid: bc2beaf82238a5249a353d02afb0edca\nfolderAsset: yes\ntimeCreated: 1514536310\nlicenseType: Free\nD"
  },
  {
    "path": "Assets/Common.meta",
    "chars": 214,
    "preview": "fileFormatVersion: 2\nguid: 0ad1543cd6efc234284c34aeefa1430a\nfolderAsset: yes\ntimeCreated: 1514536270\nlicenseType: Free\nD"
  },
  {
    "path": "Assets/FEM2D/Demo.unity",
    "chars": 9916,
    "preview": "%YAML 1.1\n%TAG !u! tag:unity3d.com,2011:\n--- !u!29 &1\nOcclusionCullingSettings:\n  m_ObjectHideFlags: 0\n  serializedVersi"
  },
  {
    "path": "Assets/FEM2D/Demo.unity.meta",
    "chars": 174,
    "preview": "fileFormatVersion: 2\nguid: 0ab61520f30dba1468adadce55fe25dd\ntimeCreated: 1488699394\nlicenseType: Pro\nDefaultImporter:\n  "
  },
  {
    "path": "Assets/FEM2D/Materials/TextureMaterial.mat",
    "chars": 2126,
    "preview": "%YAML 1.1\n%TAG !u! tag:unity3d.com,2011:\n--- !u!21 &2100000\nMaterial:\n  serializedVersion: 6\n  m_ObjectHideFlags: 0\n  m_"
  },
  {
    "path": "Assets/FEM2D/Materials/TextureMaterial.mat.meta",
    "chars": 230,
    "preview": "fileFormatVersion: 2\nguid: 716d33869f0597743928b3f83bbdbd52\ntimeCreated: 1514631150\nlicenseType: Free\nNativeFormatImport"
  },
  {
    "path": "Assets/FEM2D/Materials/TextureShader.shader",
    "chars": 937,
    "preview": "Shader \"Unlit/TextureShader\"\n{\n\tProperties\n\t{\n\t\t_MainTex (\"Texture\", 2D) = \"white\" {}\n\t}\n\tSubShader\n\t{\n\t\tTags { \"Render"
  },
  {
    "path": "Assets/FEM2D/Materials/TextureShader.shader.meta",
    "chars": 218,
    "preview": "fileFormatVersion: 2\nguid: e66837fa03fca10469cf24b483791e6d\ntimeCreated: 1514631092\nlicenseType: Free\nShaderImporter:\n  "
  },
  {
    "path": "Assets/FEM2D/Materials.meta",
    "chars": 214,
    "preview": "fileFormatVersion: 2\nguid: 6ccc40a7591015c4f914ee5ef5e031b1\nfolderAsset: yes\ntimeCreated: 1514632914\nlicenseType: Free\nD"
  },
  {
    "path": "Assets/FEM2D/Scripts/CreateCantileverBeam.cs",
    "chars": 1657,
    "preview": "using System.Collections;\nusing System.Collections.Generic;\nusing UnityEngine;\n\nusing Common.Core.LinearAlgebra;\n\nnames"
  },
  {
    "path": "Assets/FEM2D/Scripts/CreateCantileverBeam.cs.meta",
    "chars": 285,
    "preview": "fileFormatVersion: 2\nguid: 28cacb6d1b62dc240b8580f8e3b751c3\ntimeCreated: 1514597507\nlicenseType: Free\nMonoImporter:\n  ex"
  },
  {
    "path": "Assets/FEM2D/Scripts/CreateFromImage.cs",
    "chars": 6423,
    "preview": "using System.Collections;\nusing System.Collections.Generic;\nusing UnityEngine;\n\nusing Common.Core.LinearAlgebra;\n\nnames"
  },
  {
    "path": "Assets/FEM2D/Scripts/CreateFromImage.cs.meta",
    "chars": 285,
    "preview": "fileFormatVersion: 2\nguid: 9b53bb4644f88484687638a032f37ea1\ntimeCreated: 1514625832\nlicenseType: Free\nMonoImporter:\n  ex"
  },
  {
    "path": "Assets/FEM2D/Scripts/CreateRandomConvex.cs",
    "chars": 1656,
    "preview": "using System.Collections;\nusing System.Collections.Generic;\nusing UnityEngine;\n\nusing Common.Core.LinearAlgebra;\n\nnames"
  },
  {
    "path": "Assets/FEM2D/Scripts/CreateRandomConvex.cs.meta",
    "chars": 285,
    "preview": "fileFormatVersion: 2\nguid: c42a9d7090e6ce74ea170a267ecd28b4\ntimeCreated: 1514601543\nlicenseType: Free\nMonoImporter:\n  ex"
  },
  {
    "path": "Assets/FEM2D/Scripts/CreateTorus.cs",
    "chars": 1343,
    "preview": "using System.Collections;\nusing System.Collections.Generic;\nusing UnityEngine;\n\nusing Common.Core.LinearAlgebra;\n\nnames"
  },
  {
    "path": "Assets/FEM2D/Scripts/CreateTorus.cs.meta",
    "chars": 285,
    "preview": "fileFormatVersion: 2\nguid: a1f44a96f585d494c9f236e5ed6e9d11\ntimeCreated: 1514615740\nlicenseType: Free\nMonoImporter:\n  ex"
  },
  {
    "path": "Assets/FEM2D/Scripts/DelaunayTriangulation.cs",
    "chars": 7218,
    "preview": "\nusing System;\nusing System.Collections.Generic;\nusing UnityEngine;\n\nusing Common.Core.LinearAlgebra;\n\nnamespace FEM2D\r"
  },
  {
    "path": "Assets/FEM2D/Scripts/DelaunayTriangulation.cs.meta",
    "chars": 285,
    "preview": "fileFormatVersion: 2\nguid: 20ef28c4aeb64764d857a7de84df261f\ntimeCreated: 1514598499\nlicenseType: Free\nMonoImporter:\n  ex"
  },
  {
    "path": "Assets/FEM2D/Scripts/FEMDemo.cs",
    "chars": 10693,
    "preview": "using System.Collections;\nusing System.Collections.Generic;\nusing UnityEngine;\n\nusing Common.Core.LinearAlgebra;\n\nnames"
  },
  {
    "path": "Assets/FEM2D/Scripts/FEMDemo.cs.meta",
    "chars": 608,
    "preview": "fileFormatVersion: 2\nguid: 21b56fa4ac510b34d865a6cae689b006\ntimeCreated: 1514697612\nlicenseType: Free\nMonoImporter:\n  ex"
  },
  {
    "path": "Assets/FEM2D/Scripts/FEMElement.cs",
    "chars": 863,
    "preview": "using System;\nusing System.Collections.Generic;\nusing UnityEngine;\n\nusing Common.Core.LinearAlgebra;\n\nnamespace FEM2D\r\n"
  },
  {
    "path": "Assets/FEM2D/Scripts/FEMElement.cs.meta",
    "chars": 285,
    "preview": "fileFormatVersion: 2\nguid: 29457e410e915114ebb5a9f738e34e06\ntimeCreated: 1514543113\nlicenseType: Free\nMonoImporter:\n  ex"
  },
  {
    "path": "Assets/FEM2D/Scripts/FEMFractureEvent.cs",
    "chars": 257,
    "preview": "using System;\nusing System.Collections.Generic;\nusing UnityEngine;\n\nusing Common.Core.LinearAlgebra;\n\nnamespace FEM2D\r\n"
  },
  {
    "path": "Assets/FEM2D/Scripts/FEMFractureEvent.cs.meta",
    "chars": 285,
    "preview": "fileFormatVersion: 2\nguid: 44af2fa5db0b53846894b4e1292f6fe9\ntimeCreated: 1514543146\nlicenseType: Free\nMonoImporter:\n  ex"
  },
  {
    "path": "Assets/FEM2D/Scripts/FEMParticle.cs",
    "chars": 1052,
    "preview": "using System;\nusing System.Collections.Generic;\nusing UnityEngine;\n\nusing Common.Core.LinearAlgebra;\n\nnamespace FEM2D\r\n"
  },
  {
    "path": "Assets/FEM2D/Scripts/FEMParticle.cs.meta",
    "chars": 285,
    "preview": "fileFormatVersion: 2\nguid: 6944fa5b6e65d92449bcb768b46dba06\ntimeCreated: 1514543104\nlicenseType: Free\nMonoImporter:\n  ex"
  },
  {
    "path": "Assets/FEM2D/Scripts/FEMScene.cs",
    "chars": 11599,
    "preview": "using System;\nusing System.Collections.Generic;\nusing UnityEngine;\n\nusing Common.Core.LinearAlgebra;\nusing Common.Mathe"
  },
  {
    "path": "Assets/FEM2D/Scripts/FEMScene.cs.meta",
    "chars": 262,
    "preview": "fileFormatVersion: 2\nguid: da2457346ca976a47ba80cc04748d813\ntimeCreated: 1488701314\nlicenseType: Pro\nMonoImporter:\n  ser"
  },
  {
    "path": "Assets/FEM2D/Scripts/Mesher.cs",
    "chars": 5484,
    "preview": "using System;\nusing System.Collections.Generic;\nusing UnityEngine;\n\nusing Common.Core.LinearAlgebra;\n\nnamespace FEM2D\r\n"
  },
  {
    "path": "Assets/FEM2D/Scripts/Mesher.cs.meta",
    "chars": 285,
    "preview": "fileFormatVersion: 2\nguid: 0aec6e65a8759ea44b63d58e7680ddad\ntimeCreated: 1514598008\nlicenseType: Free\nMonoImporter:\n  ex"
  },
  {
    "path": "Assets/FEM2D/Scripts/Triangle.cs",
    "chars": 339,
    "preview": "using System;\nusing System.Collections.Generic;\nusing UnityEngine;\n\nusing Common.Core.LinearAlgebra;\n\nnamespace FEM2D\r\n"
  },
  {
    "path": "Assets/FEM2D/Scripts/Triangle.cs.meta",
    "chars": 285,
    "preview": "fileFormatVersion: 2\nguid: 35ec53c1f7d74e54fbf9b83612e93df7\ntimeCreated: 1514543471\nlicenseType: Free\nMonoImporter:\n  ex"
  },
  {
    "path": "Assets/FEM2D/Scripts.meta",
    "chars": 214,
    "preview": "fileFormatVersion: 2\nguid: 6a97a42ecbc1e4149bb3100fd18cc420\nfolderAsset: yes\ntimeCreated: 1514543123\nlicenseType: Free\nD"
  },
  {
    "path": "Assets/FEM2D/Textures/armadillo.png.meta",
    "chars": 1876,
    "preview": "fileFormatVersion: 2\nguid: 8d4354cace070ef41a318c34670ff88a\ntimeCreated: 1514625724\nlicenseType: Free\nTextureImporter:\n "
  },
  {
    "path": "Assets/FEM2D/Textures/bunny.png.meta",
    "chars": 1876,
    "preview": "fileFormatVersion: 2\nguid: 689440ccb80c6a348afee121dd2fa9e3\ntimeCreated: 1514625724\nlicenseType: Free\nTextureImporter:\n "
  },
  {
    "path": "Assets/FEM2D/Textures/donut1.png.meta",
    "chars": 1876,
    "preview": "fileFormatVersion: 2\nguid: 4df4a7e175870f94ca81a95b3d9c28f4\ntimeCreated: 1514625724\nlicenseType: Free\nTextureImporter:\n "
  },
  {
    "path": "Assets/FEM2D/Textures.meta",
    "chars": 214,
    "preview": "fileFormatVersion: 2\nguid: 7a3c443360e76cc4a856e4c16eaccd25\nfolderAsset: yes\ntimeCreated: 1514625721\nlicenseType: Free\nD"
  },
  {
    "path": "Assets/FEM2D.meta",
    "chars": 214,
    "preview": "fileFormatVersion: 2\nguid: 7abf378388cbc1e42a90855390a552b4\nfolderAsset: yes\ntimeCreated: 1514536684\nlicenseType: Free\nD"
  },
  {
    "path": "LICENSE",
    "chars": 2145,
    "preview": "MIT License\n\nCopyright (c) 2017 Justin\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof "
  },
  {
    "path": "Packages/manifest.json",
    "chars": 1720,
    "preview": "{\n  \"dependencies\": {\n    \"com.unity.collab-proxy\": \"1.3.9\",\n    \"com.unity.ide.rider\": \"1.2.1\",\n    \"com.unity.ide.visu"
  },
  {
    "path": "Packages/packages-lock.json",
    "chars": 8589,
    "preview": "{\n  \"dependencies\": {\n    \"com.unity.collab-proxy\": {\n      \"version\": \"1.3.9\",\n      \"depth\": 0,\n      \"source\": \"regis"
  },
  {
    "path": "ProjectSettings/AudioManager.asset",
    "chars": 413,
    "preview": "%YAML 1.1\n%TAG !u! tag:unity3d.com,2011:\n--- !u!11 &1\nAudioManager:\n  m_ObjectHideFlags: 0\n  serializedVersion: 2\n  m_Vo"
  },
  {
    "path": "ProjectSettings/ClusterInputManager.asset",
    "chars": 114,
    "preview": "%YAML 1.1\n%TAG !u! tag:unity3d.com,2011:\n--- !u!236 &1\nClusterInputManager:\n  m_ObjectHideFlags: 0\n  m_Inputs: []\n"
  },
  {
    "path": "ProjectSettings/DynamicsManager.asset",
    "chars": 1294,
    "preview": "%YAML 1.1\n%TAG !u! tag:unity3d.com,2011:\n--- !u!55 &1\nPhysicsManager:\n  m_ObjectHideFlags: 0\n  serializedVersion: 13\n  m"
  },
  {
    "path": "ProjectSettings/EditorBuildSettings.asset",
    "chars": 160,
    "preview": "%YAML 1.1\n%TAG !u! tag:unity3d.com,2011:\n--- !u!1045 &1\nEditorBuildSettings:\n  m_ObjectHideFlags: 0\n  serializedVersion:"
  },
  {
    "path": "ProjectSettings/EditorSettings.asset",
    "chars": 1219,
    "preview": "%YAML 1.1\n%TAG !u! tag:unity3d.com,2011:\n--- !u!159 &1\nEditorSettings:\n  m_ObjectHideFlags: 0\n  serializedVersion: 11\n  "
  },
  {
    "path": "ProjectSettings/GraphicsSettings.asset",
    "chars": 2279,
    "preview": "%YAML 1.1\n%TAG !u! tag:unity3d.com,2011:\n--- !u!30 &1\nGraphicsSettings:\n  m_ObjectHideFlags: 0\n  serializedVersion: 13\n "
  },
  {
    "path": "ProjectSettings/InputManager.asset",
    "chars": 5793,
    "preview": "%YAML 1.1\n%TAG !u! tag:unity3d.com,2011:\n--- !u!13 &1\nInputManager:\n  m_ObjectHideFlags: 0\n  serializedVersion: 2\n  m_Ax"
  },
  {
    "path": "ProjectSettings/NavMeshAreas.asset",
    "chars": 1363,
    "preview": "%YAML 1.1\n%TAG !u! tag:unity3d.com,2011:\n--- !u!126 &1\nNavMeshProjectSettings:\n  m_ObjectHideFlags: 0\n  serializedVersio"
  },
  {
    "path": "ProjectSettings/PackageManagerSettings.asset",
    "chars": 1003,
    "preview": "%YAML 1.1\n%TAG !u! tag:unity3d.com,2011:\n--- !u!114 &1\nMonoBehaviour:\n  m_ObjectHideFlags: 61\n  m_CorrespondingSourceObj"
  },
  {
    "path": "ProjectSettings/Physics2DSettings.asset",
    "chars": 2028,
    "preview": "%YAML 1.1\n%TAG !u! tag:unity3d.com,2011:\n--- !u!19 &1\nPhysics2DSettings:\n  m_ObjectHideFlags: 0\n  serializedVersion: 5\n "
  },
  {
    "path": "ProjectSettings/PresetManager.asset",
    "chars": 146,
    "preview": "%YAML 1.1\n%TAG !u! tag:unity3d.com,2011:\n--- !u!1386491679 &1\nPresetManager:\n  m_ObjectHideFlags: 0\n  serializedVersion:"
  },
  {
    "path": "ProjectSettings/ProjectSettings.asset",
    "chars": 17438,
    "preview": "%YAML 1.1\n%TAG !u! tag:unity3d.com,2011:\n--- !u!129 &1\nPlayerSettings:\n  m_ObjectHideFlags: 0\n  serializedVersion: 20\n  "
  },
  {
    "path": "ProjectSettings/ProjectVersion.txt",
    "chars": 83,
    "preview": "m_EditorVersion: 2020.1.6f1\nm_EditorVersionWithRevision: 2020.1.6f1 (fc477ca6df10)\n"
  },
  {
    "path": "ProjectSettings/QualitySettings.asset",
    "chars": 6665,
    "preview": "%YAML 1.1\n%TAG !u! tag:unity3d.com,2011:\n--- !u!47 &1\nQualitySettings:\n  m_ObjectHideFlags: 0\n  serializedVersion: 5\n  m"
  },
  {
    "path": "ProjectSettings/TagManager.asset",
    "chars": 378,
    "preview": "%YAML 1.1\n%TAG !u! tag:unity3d.com,2011:\n--- !u!78 &1\nTagManager:\n  serializedVersion: 2\n  tags: []\n  layers:\n  - Defaul"
  },
  {
    "path": "ProjectSettings/TimeManager.asset",
    "chars": 202,
    "preview": "%YAML 1.1\n%TAG !u! tag:unity3d.com,2011:\n--- !u!5 &1\nTimeManager:\n  m_ObjectHideFlags: 0\n  Fixed Timestep: 0.02\n  Maximu"
  },
  {
    "path": "ProjectSettings/UnityConnectSettings.asset",
    "chars": 853,
    "preview": "%YAML 1.1\n%TAG !u! tag:unity3d.com,2011:\n--- !u!310 &1\nUnityConnectSettings:\n  m_ObjectHideFlags: 0\n  serializedVersion:"
  },
  {
    "path": "ProjectSettings/VFXManager.asset",
    "chars": 353,
    "preview": "%YAML 1.1\n%TAG !u! tag:unity3d.com,2011:\n--- !u!937362698 &1\nVFXManager:\n  m_ObjectHideFlags: 0\n  m_IndirectShader: {fil"
  },
  {
    "path": "ProjectSettings/VersionControlSettings.asset",
    "chars": 188,
    "preview": "%YAML 1.1\n%TAG !u! tag:unity3d.com,2011:\n--- !u!890905787 &1\nVersionControlSettings:\n  m_ObjectHideFlags: 0\n  m_Mode: Vi"
  },
  {
    "path": "ProjectSettings/XRSettings.asset",
    "chars": 158,
    "preview": "{\n    \"m_SettingKeys\": [\n        \"VR Device Disabled\",\n        \"VR Device User Alert\"\n    ],\n    \"m_SettingValues\": [\n  "
  },
  {
    "path": "README.md",
    "chars": 1600,
    "preview": "# 2D-Deformable-body-in-Unity\nA 2D Deformable body simulation in Unity using FEM\n\nThis a port of the 2D FEM project by ["
  }
]

About this extraction

This page contains the full source code of the Scrawk/2D-Deformable-body-in-Unity GitHub repository, extracted and formatted as plain text for AI agents and large language models (LLMs). The extraction includes 116 files (425.4 KB), approximately 128.1k tokens, and a symbol index with 514 extracted functions, classes, methods, constants, and types. Use this with OpenClaw, Claude, ChatGPT, Cursor, Windsurf, or any other AI tool that accepts text input. You can copy the full output to your clipboard or download it as a .txt file.

Extracted by GitExtract — free GitHub repo to text converter for AI. Built by Nikandr Surkov.

Copied to clipboard!