Plot coordinates along a rhumbline between two points to determine line-of-sight

George Fendler
George Fendler used Ask the Experts™
on
Well, I thought this would be the easy part of this project. Turns out I was wrong.
I am writing a program that will determine line-of-sight between two prospective points for microwave radio reception.
If I know the coordinates of point "A" and point "B", How can I calculate multiple points between them. Depending upon the terrain, I will need to increase the density of the sampling points.
For example, I know the starting point is at 36.919506, -121.341454. The destination is at 36.919506, -121.341454 .

How can I get the coordinates for points every 200 ft along this path? 500 ft.?
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Are you interested in an algorithm or does it have to be expressed in PHP?
George Fendlerprogrammer

Author

Commented:
An algorithm would do the job. I think I should be able to wrap some php around it.
OK, I'm stuck.  I can get the incremental points on the line but I don't have it in feet because the number of feet represented by .001 (for example) varies based on the latitude and longitude.   Is that the part you were stuck on too?  

I think it would be useful if you are only interested in the density of the sampling points (for example, you want 25 equidistant points).  But if you are looking to space them a certain number of feet apart, it won't do you much good.
Also, I've been working with straight lines, not rhumblines.  I completely misunderstood the question.  Sorry I wasn't able to be of any assistance.

If I were you I would ask this question under math & science and algorithims.

Good luck!
George Fendlerprogrammer

Author

Commented:
For the most part, the distances will be under 8 miles. At that short distance, a rhumbline should be very close to a straight line. I am trying to determine line of sight, so a straight line is logically what I need (whatever straight is on an arc). I used rhumbline to avoid great circle lines which are definately not straight and I found a number of formula that used them. However, my trig is not so good so that's why I was asking for help. I didn't kow there was a math&science algorithms section. I will check it out.
Here is some c# code, I hope it helps.  It produced the following output

036.91950600, -121.34145400
036.91955540, -121.34150860
036.91960480, -121.34156320
036.91965420, -121.34161780
036.91970360, -121.34167240
036.91975300, -121.34172700
036.91980240, -121.34178160
036.91985180, -121.34183620
036.91990120, -121.34189080
036.91995060, -121.34194540
036.92000000, -121.34200000

        // converts range of latitude from -90, +90 to 0, 1.
        private double NormalFromLatitude(double lat)
        {
            if (lat < -90 || lat > 90) throw new Exception("Invalid");
            return (lat + 90) / 180;
        }

        // converts range of longitude from -180, +180 to 0, 1.
        private double NormalFromLongitude(double lon)
        {
            if (lon < -180 || lon > 180) throw new Exception("Invalid");
            return (lon + 180) / 360;
        }

        // converts range of latitude from 0,1 to -90, +90.
        private double LatitudeFromNormal(double lat)
        {
            if (lat < 0 || lat > 1) throw new Exception("Invalid");
            return (lat * 180) - 90;
        }

        // converts range of longitude from 0, 1 to -180, +180.
        private double LongitudeFromNormal(double lon)
        {
            if (lon < 0 || lon > 1) throw new Exception("Invalid");
            return (lon * 360) - 180;
        }

        private PointD ToNormalPoint(PointD p)
        {
            return new PointD(NormalFromLatitude(p.X), NormalFromLongitude(p.Y));
        }

        private PointD FromNormalPoint(PointD normalPoint)
        {
            return new PointD(LatitudeFromNormal(normalPoint.X), LongitudeFromNormal(normalPoint.Y));
        }

        private void DisplayPoint(PointD normalPoint)
        {
            PointD p = FromNormalPoint(normalPoint);
            string s = string.Format("{0:000.00000000}, {1:000.00000000}", p.X, p.Y);
            DisplayLine(s);
        }

        private void Main_Load(object sender, EventArgs e)
        {            
            PointD startPoint = new PointD(36.919506, -121.341454);
            PointD endPoint   = new PointD(36.920,    -121.342);
            PointD startNormalPoint = ToNormalPoint(startPoint);
            PointD endNormalPoint   = ToNormalPoint(endPoint);
            double dx = endNormalPoint.X - startNormalPoint.X;  // get delta x          
            double dy = endNormalPoint.Y - startNormalPoint.Y; // get delta y
            double a = Math.Atan2(dy, dx); // calculate the angle of the line
            double cosA = Math.Cos(a); // get the cosine
            double sinA = Math.Sin(a); // get the sine
            double distance = Math.Sqrt(Math.Pow(dx, 2) + Math.Pow(dy, 2));            
            int n = 10; // number of points
            double distanceBetweenPoints = distance / n;                                              
            for (double d = 0; d <= distance; d += distanceBetweenPoints)
            {
                double x = startNormalPoint.X + d * cosA;
                double y = startNormalPoint.Y + d * sinA;
                DisplayPoint(new PointD(x,y));
            }                        
        }
George Fendlerprogrammer

Author

Commented:
Excellent solution. Now all I need to do is translate it into PHP.
Thanks
Glad I was able to help after all - good luck!

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial