0

I have a mission to calculate point on a Map. I have the start point, the angle and the distance from the point. How can I do it ? I search a lot I found something but it doesn't work good - I mean it it doesn't calculate the correct point. Thank's all.

My try :

public Point MesPoint(double x1, double x2, double y1, double y2, double distance, double x) // X is the angle
{
    double xEndP, yEndP;
    var angularDistance = distance / c_EarthRadiusInKilometers; // angular distance in radians
    var lat = ToRadian(y2);
    var lon = ToRadian(x2);
    var angel = ToRadian(x);

    double latRadians = Math.Asin((Math.Sin(lat) * Math.Cos(angularDistance)) + (Math.Cos(lat) * Math.Sin(angularDistance) * Math.Cos(angel)));
    double lngRadians = Math.Atan2(
                            Math.Sin(angel) * Math.Sin(angularDistance) * Math.Cos(lat),
                            Math.Cos(angularDistance) - (Math.Sin(lat) * Math.Sin(latRadians)));


    double lon1 = (lon + lngRadians + Math.PI) % (2 * Math.PI) - Math.PI; // normalise to -180..+180º

    yEndP = ToDegrees(latRadians);
    xEndP = ToDegrees(lon1);
    return (new Point(xEndP, yEndP));
}
Daniel Kelley
  • 7,579
  • 6
  • 42
  • 50
  • You are just trying to calculate the final point? This seems more like a math question than a programming question. – Matt Burland Jan 06 '15 at 15:05
  • *I mean it it doesn't calculate the correct point* Some examples of outputs, expected and actual, might help diagnose the problem. – High Performance Mark Jan 06 '15 at 15:08
  • _"I have the start point, the angle and the distance from the point"_. Ok, which of those correspond to which of the arguments in your function? what's x1,y1, and what's x2,y2? Also, are you calculating distances on a flat plane, or does this need to work on a sphere? – Kevin Jan 06 '15 at 15:08
  • What I understand is that you try to compute the latitude and longitude of a point that's at `distance` from (x2,y2). But you never use (x1,y1) and I don't see what your angle `x` should be used for. Can you clarify ? – Cimbali Jan 06 '15 at 17:21
  • If `x` is a bearing, this is possibly what you are looking for : http://stackoverflow.com/questions/2187657/calculate-second-point-knowing-the-starting-point-and-distance – Cimbali Jan 06 '15 at 17:52
  • Actually, no it doesn't help me the code there doesn't work's good for me. It calculate point that isn't on the line length. What can i do ? – SOFProjectector Jan 06 '15 at 21:51
  • Well for starters, you could answer all the questions about what exactly you are trying to do, and what your parameters are and what they should do. A drawing would be a great idea, I think. – Cimbali Jan 07 '15 at 03:36

0 Answers0