Engines/FlatRedBallXNA/FlatRedBall/Math/Geometry/Polygon.cs
/// <summary>
/// Returns a vector from the argument vector to the closest point on the Polygon's edges. This method considers
/// only the perimeter, so an argument point inside the polygon will still return a non-zero-length vector.
/// </summary>
/// <param name="vector">The point to start from.</param>
/// <returns>A vector representing the distance from the argument vector to this.</returns>
Returns a vector from the argument vector to the closest point on the Polygon's edges. This method considers
only the perimeter, so an argument point inside the polygon will still return a non-zero-length vector.
Returns a vector from the argument vector to the closest point on the Polygon ' s edges . This method considers only the perimeter so an argument point inside the polygon will still return a non - zero - length vector .
public Point3D VectorFrom(Point3D vector)
        {
            double minDistance = double.PositiveInfinity;
            double tempMinDistance;
            Point3D vectorToReturn = new Point3D();
            if (mVertices.Length == 1)
            {
                return new Point3D(
                    mVertices[0].Position.X - vector.X,
                    mVertices[0].Position.Y - vector.Y,
                    mVertices[0].Position.Z - vector.Z);
            }
            Segment connectingSegment = new Segment();
            Segment segment = new Segment();
            for (int i = 0; i < mVertices.Length - 1; i++)
            {
                int afterI = i + 1;
                segment.Point1 = new Point(mVertices[i].Position.X, mVertices[i].Position.Y);
                segment.Point2 = new Point(mVertices[afterI].Position.X, mVertices[afterI].Position.Y);
                tempMinDistance = segment.DistanceTo(new Point(vector.X, vector.Y), out connectingSegment);
                if (tempMinDistance < minDistance)
                {
                    minDistance = tempMinDistance;
                    vectorToReturn = new Point3D(
                        connectingSegment.Point2.X - connectingSegment.Point1.X,
                        connectingSegment.Point2.Y - connectingSegment.Point1.Y,
                        0);
                }
            }
            return vectorToReturn;
        }
public Point3D VectorFrom ( Point3D vector ) { double minDistance = double . PositiveInfinity ; double tempMinDistance ; Point3D vectorToReturn = new Point3D ( ) ; if ( mVertices . Length == 1 ) { return new Point3D ( mVertices [ 0 ] . Position . X - vector . X , mVertices [ 0 ] . Position . Y - vector . Y , mVertices [ 0 ] . Position . Z - vector . Z ) ; } Segment connectingSegment = new Segment ( ) ; Segment segment = new Segment ( ) ; for ( int i = 0 ; i < mVertices . Length - 1 ; i ++ ) { int afterI = i + 1 ; segment . Point1 = new Point ( mVertices [ i ] . Position . X , mVertices [ i ] . Position . Y ) ; segment . Point2 = new Point ( mVertices [ afterI ] . Position . X , mVertices [ afterI ] . Position . Y ) ; tempMinDistance = segment . DistanceTo ( new Point ( vector . X , vector . Y ) , out connectingSegment ) ; if ( tempMinDistance < minDistance ) { minDistance = tempMinDistance ; vectorToReturn = new Point3D ( connectingSegment . Point2 . X - connectingSegment . Point1 . X , connectingSegment . Point2 . Y - connectingSegment . Point1 . Y , 0 ) ; } } return vectorToReturn ; }
Returns a vector from the argument vector to the closest point on the Polygon's edges.
Returns a vector from the argument vector to the closest point on the Polygon ' s edges .
A vector representing the distance from the argument vector to this.
A vector representing the distance from the argument vector to this .
vector
Point3D
The point to start from.
The point to start from .