Perpendicular on a line from a given point

前端 未结 14 1541
名媛妹妹
名媛妹妹 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

    0 讨论(0)
  • 2020-11-29 19:28

    Mathematica introduced the function RegionNearest[] in version 10, 2014. This function could be used to return an answer to this question:

    {x4,y4} = RegionNearest[Line[{{x1,y1},{x2,y2}}],{x3,y3}]
    
    0 讨论(0)
提交回复
热议问题