Calculate if position is on direct line between two points

Former Member
Former Member
Hello together, I'm currently developing an app in which I need to calculate some values based on GPS coordinates. One thing I struggle to get working is the following: I have two coordinates that have a virtual line between them. What I want to calculate now is how far I am away from the closest point on that line.
  • I'm missing one value for that. With the formula for Cross-track distance I got the distance from my current position but not the actual position on the line. To calculate that position I would need a bearing and to calculate a bearing I would need the position. At least if I use the given formulas on that site.


    What value are you trying to get? Assume for a second that A was the start point, B is the target, X is the current position, and Y is the point on the segment A-B closest to X...

    X
    |
    |
    |
    A----Y---------------------------------------B


    It seems that you are asking to calculate the bearing from X to Y, but that doesn't seem like useful information. If the user originally wanted to get from A to B, and they are now at X, it seems like they want to know how to get from X to B.
  • Former Member
    Former Member over 9 years ago
    What value are you trying to get? Assume for a second that A was the start point, B is the target, X is the current position, and Y is the point on the segment A-B closest to X...

    X
    |
    |
    |
    A----Y---------------------------------------B


    It seems that you are asking to calculate the bearing from X to Y, but that doesn't seem like useful information. If the user originally wanted to get from A to B, and they are now at X, it seems like they want to know how to get from X to B.


    You can imagine the route fom A to B as a border that the user wants to cross. So first the points A and B are marked and afterwords he wants to cross the line between them on the shortest way from his current position. This is for yacht racing and the points A and B are boys that mark the starting line.
  • Former Member
    Former Member over 9 years ago
    I have an idea on how this could possibly be calculated. Please take a look at the drawing to follow my thoughts.

    - I want to calculate the value of z
    - I assume, that the direction from C to D is always orthogonal to the direction from A to B (Only if C is between A and B otherwise its the direction from C to A or C to B, whatever is nearer)
    - This means, that the value of the angle y is 90°
    - The value of z should then be either (x + 90) % 360
    - In this case z would be 190°

  • 501

    That drawing doesn't make any sense. The sum of the angles in a triangle is always exactly 180°. If x is an angle of 100°, then y cannot possibly be 90°. In that picture it seems to me that x is supposed to be the length of the segment from A-D, and z is the length of the segment C-D, and both are mislabeled as angles.

    Travis
  • Former Member
    Former Member over 9 years ago
    That drawing doesn't make any sense. The sum of the angles in a triangle is always exactly 180°. If x is an angle of 100°, then y cannot possibly be 90°. In that picture it seems to me that x is supposed to be the length of the segment from A-D, and z is the length of the segment C-D, and both are mislabeled as angles.

    Travis


    Sorry that I made this so confusing. x is not an angle inside the triangle, it is the compass direction from A to B. And x is definately supposed to be the compass direction from A to B (I drew this and I absolutely sure, that is what I want). My assumption is, that the shortest way always differs by 90° (the angle y inside the triangle ). z is also not mislabled. That is the value I want to calculate. It is the compass direction from C to D. I'm pretty sure this is right.