Distance From Point To Line : Geometry « Development Class « C# / C Sharp






Distance From Point To Line

         

using System;

namespace ComputationalGeometry.Shapes
{
    public static class MathUtility
    {


        public static double DistanceFromPointToLine(Point2D point, Line2D line)
        {
            // given a line based on two points, and a point away from the line,
            // find the perpendicular distance from the point to the line.
            // see http://mathworld.wolfram.com/Point-LineDistance2-Dimensional.html
            // for explanation and defination.
            Point2D l1 = line.InitialPoint;
            Point2D l2 = line.TerminalPoint;

            return Math.Abs((l2.X - l1.X)*(l1.Y - point.Y) - (l1.X - point.X)*(l2.Y - l1.Y))/
                    Math.Sqrt(Math.Pow(l2.X - l1.X, 2) + Math.Pow(l2.Y - l1.Y, 2));
        }
    }
}

   
    
    
    
    
    
    
    
    
  








Related examples in the same category

1.Convert Meters To Inches
2.Convert Meters To Miles
3.Get Steps FromD istance And Stride
4.Convert Miles To Meters
5.Distance Util
6.PointD
7.Calculate Gradient Angle
8.Convert Meters To Feet
9.Get distance between two points
10.Tests if two line segments intersect or not.
11.Sorts a graph by the dependencies.
12.Degrees To Radians
13.Radians To Degrees
14.Angles Difference
15.Degrees To Radians and Radians To Degrees
16.Get Distance From Steps
17.Meter to feet and feet to Mile