AForge.Math.Geometry.Line.DistanceToPoint C# (CSharp) Method

DistanceToPoint() public method

Calculate Euclidean distance between a point and a line.
public DistanceToPoint ( Point point ) : float
point Point The point to calculate distance to.
return float
		public float DistanceToPoint( Point point )
		{
			float distance;

			if ( !IsVertical )
			{
				float div = (float) Math.Sqrt( k * k + 1 );
				distance = Math.Abs( ( k * point.X + b - point.Y ) / div );
			}
			else
			{
				distance = Math.Abs( b - point.X );
			}

			return distance;
		}

Usage Example

Example #1
0
        public float DistanceToPoint(Point point)
        {
            switch (LocateProjection(point))
            {
            case ProjectionLocation.RayA:
                return(point.DistanceTo(start));

            case ProjectionLocation.RayB:
                return(point.DistanceTo(end));

            default:
                return(line.DistanceToPoint(point));
            }
        }
All Usage Examples Of AForge.Math.Geometry.Line::DistanceToPoint