Exemplo n.º 1
0
        public static Vector3 ComputeNormal(Matrix <float> eigenVectors, MNLA.Vector <Complex> eigenValue)
        {
            // Keep the smallest eigenvector as surface normal.
            int   smallestIndex = 0;
            float smallestValue = float.MaxValue;

            for (int j = 0; j < eigenVectors.ColumnCount; j++)
            {
                float lambda = (float)eigenValue[j].Real;
                if (lambda < smallestValue)
                {
                    smallestIndex = j;
                    smallestValue = lambda;
                }
            }

            var normalVector = eigenVectors.Column(smallestIndex);

            return(normalVector.Normalize(2).ToVector3());
        }
Exemplo n.º 2
0
        public static MNLA.Vector <float> CrossProduct(this MNLA.Vector <float> left, MNLA.Vector <float> right, bool normalize = true)
        {
            if ((left.Count != 3 || right.Count != 3))
            {
                throw new Exception("Vectors must have a length of 3.");
            }

            MNLA.Vector <float> result = MNLA.Vector <float> .Build.Dense(3);

            result[0] = left[1] * right[2] - left[2] * right[1];
            result[1] = -left[0] * right[2] + left[2] * right[0];
            result[2] = left[0] * right[1] - left[1] * right[0];

            if (normalize)
            {
                result = result.Normalize(2);
            }

            return(result);
        }
Exemplo n.º 3
0
 public static Vector3 ToVector3(this MNLA.Vector <float> v)
 {
     return(new Vector3(v[0], v[1], v[2]));
 }