Dot() public static method

public static Dot ( Point p1, Point p2 ) : double
p1 Point
p2 Point
return double
Esempio n. 1
0
        public float DistanceTo(Point point, out Segment connectingSegment)
        {
            double segmentLength = GetLength();

            Point normalizedLine = new Point(
                (Point2.X - Point1.X) / segmentLength,
                (Point2.Y - Point1.Y) / segmentLength);

            Point pointVector = new Point(point.X - Point1.X, point.Y - Point1.Y);

            double length = Point.Dot(pointVector, normalizedLine);

            connectingSegment.Point1 = point;
            if (length < 0)
            {
                connectingSegment.Point2 = Point1;
            }
            else if (length > segmentLength)
            {
                connectingSegment.Point2 = Point2;
            }
            else
            {
                connectingSegment.Point2 = new Point(Point1.X + length * normalizedLine.X,
                                                     Point1.Y + length * normalizedLine.Y);
            }

            return((float)connectingSegment.GetLength());
        }