GetLength() public method

Returns the length of the segment.
public GetLength ( ) : double
return double
Exemplo 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());
        }
Exemplo n.º 2
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();
        }