Accord.Math.Geometry.LineSegment.DistanceToPoint C# (CSharp) Метод

DistanceToPoint() публичный Метод

Calculate Euclidean distance between a point and a finite line segment.
public DistanceToPoint ( System.Point point ) : float
point System.Point The point to calculate the distance to.
Результат float
        public float DistanceToPoint(Point point)
        {
            float segmentDistance;

            switch (LocateProjection(point))
            {
                case ProjectionLocation.RayA:
                    segmentDistance = point.DistanceTo(start);
                    break;
                case ProjectionLocation.RayB:
                    segmentDistance = point.DistanceTo(end);
                    break;
                default:
                    segmentDistance = line.DistanceToPoint(point);
                    break;
            };

            return segmentDistance;
        }

Usage Example

Пример #1
0
        public void DistanceToPointTest( float x, float y, float x1, float y1, float x2, float y2, float expectedDistance )
        {
            Point pt = new Point( x, y );
            Point pt1 = new Point( x1, y1 );
            Point pt2 = new Point( x2, y2 );
            LineSegment segment = new LineSegment( pt1, pt2 );

            Assert.AreEqual( expectedDistance, segment.DistanceToPoint( pt ) );
        }