Search code examples
coordinatesesripolyline

Finding the tangent on a given point of a polyline


I have a list of X,Y coordinates that represents a road. For every 5 meters, I need to calculate the angle of the tangent on this road, as I have tried to illustrate in the image.tangents of road

My problem is that this road is not represented by a mathematical function that I can simply derive, it is represented by a list of coordinates (UTM33N).

In my other similar projects we use ArcGIS/ESRI libraries to perform geographical functions such as this, but in this project I need to be independent of any software that require the end user to have a license, so I need to do the calculations myself (or find a free/open source library that can do it).

I am using a cubic spline function to make the line rounded between the coordinates, since all tangents on a line segment would just be parallell to the segment otherwise.

But now I am stuck. I am considering simply calculating the angle between any three points on the line (given enough points), and using this to find the tangents, but that doesn't sound like a good method. Any suggestions?


Solution

  • In the end, I concluded that the points were plentiful enough to give an accurate angle using simple geometry:

            //Calculate delta values
            var dx = next.X - curr.X;
            var dy = next.Y - curr.Y;
            var dz = next.Z - curr.Z;
    
            //Calculate horizontal and 3D length of this segment.
            var hLength = Math.Sqrt(dx * dx + dy * dy);
            var length = Math.Sqrt(hLength * hLength + dz * dz);
    
            //Calculate horizontal and vertical angles.
            hAngle = Math.Atan(dy/dx);
            vAngle = Math.Atan(dz/hLength);