FindNormalVector() 공개 메소드

Finds normal vector of a hyper-plane given by vertices. Stores the results to normalData.
public FindNormalVector ( int vertices, double normalData ) : void
vertices int
normalData double
리턴 void
예제 #1
0
        /// <summary>
        /// Calculates the normal and offset of the hyper-plane given by the face's vertices.
        /// </summary>
        /// <param name="face"></param>
        /// <returns></returns>
        private bool CalculateFacePlane(ConvexFaceInternal face)
        {
            var vertices = face.Vertices;
            var normal   = face.Normal;

            MathHelper.FindNormalVector(vertices, normal);

            if (double.IsNaN(normal[0]))
            {
                return(false);
            }

            double offset         = 0.0;
            double centerDistance = 0.0;
            var    fi             = vertices[0].PositionData;

            for (int i = 0; i < Dimension; i++)
            {
                double n = normal[i];
                offset         += n * fi[i];
                centerDistance += n * Center[i];
            }
            face.Offset     = -offset;
            centerDistance -= offset;

            if (centerDistance > 0)
            {
                for (int i = 0; i < Dimension; i++)
                {
                    normal[i] = -normal[i];
                }
                face.Offset          = offset;
                face.IsNormalFlipped = true;
            }
            else
            {
                face.IsNormalFlipped = false;
            }

            return(true);
        }
예제 #2
0
        /// <summary>
        /// Calculates the normal and offset of the hyper-plane given by the face's pointCloud.
        /// </summary>
        /// <param name="face"></param>
        /// <returns></returns>
        private bool CalculateFacePlane(ConvexFaceInternal face)
        {
            var pointCloud = face.Vertices;
            var normal     = face.Normal;

            MathHelper.FindNormalVector(pointCloud, normal);

            if (float.IsNaN(normal[0]))
            {
                return(false);
            }

            float offset         = 0.0f;
            float centerDistance = 0.0f;
            var   fi             = pointCloud[0].PositionData;

            for (int i = 0; i < Dimension; i++)
            {
                float n = normal[i];
                offset         += n * fi[i];
                centerDistance += n * Center[i];
            }
            face.Offset     = -offset;
            centerDistance -= offset;

            if (centerDistance > 0)
            {
                for (int i = 0; i < Dimension; i++)
                {
                    normal[i] = -normal[i];
                }
                face.Offset          = offset;
                face.IsNormalFlipped = true;
            }
            else
            {
                face.IsNormalFlipped = false;
            }

            return(true);
        }