Perpendicular on a line from a given point

前端 未结 14 1657
名媛妹妹
名媛妹妹 2020-11-29 18:34

How can I draw a perpendicular on a line segment from a given point? My line segment is defined as (x1, y1), (x2, y2), If I draw a perpendicular from a point (x3,y3) and it

14条回答
  •  悲&欢浪女
    2020-11-29 19:27

    This is a C# implementation of the accepted answer. It's also using ArcGis to return a MapPoint as that's what we're using for this project.

            private MapPoint GenerateLinePoint(double startPointX, double startPointY, double endPointX, double endPointY, double pointX, double pointY)
            {
                double k = ((endPointY - startPointY) * (pointX - startPointX) - (endPointX - startPointX) * (pointY - startPointY)) / (Math.Pow(endPointY - startPointY, 2) 
                    + Math.Pow(endPointX - startPointX, 2));
                double resultX = pointX - k * (endPointY - startPointY);
                double resultY = pointY + k * (endPointX - startPointX);
    
                return new MapPoint(resultX, resultY, 0, SpatialReferences.Wgs84);
            }
    

    Thanks to Ray as this worked perfectly for me. c#arcgis

提交回复
热议问题