Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modify the greatArcIntermediaryPoint function in util.ts #1304

Closed
wants to merge 1 commit into from

Conversation

HapDragon
Copy link

Modify the greatArcIntermediaryPoint function, because there may be some problem in calculating r.

Merge request checklist

  • All lints and tests pass. If needed, new unit tests were added.
  • If needed, the documentation has been updated.

Modify the greatArcIntermediaryPoint function, because there may be some problem in calculating r.
@mistic100
Copy link
Owner

According to the linked article, the correct computation is

      // distance between points
        const Δφ = φ2 - φ1;
        const Δλ = λ2 - λ1;
        const a = Math.sin(Δφ/2) * Math.sin(Δφ/2)
            + Math.cos(φ1) * Math.cos(φ2) * Math.sin(Δλ/2) * Math.sin(Δλ/2);
        const δ = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a));

no idea where your version come from


however I compared the results :

  • current: [-1.877653919666705,-0.38152789807555176]
  • new: [-1.877661200390654,-0.38152577113488884]

it only differs by 0.00001 rads

given is only used to comput the middle point of polylines which is only used for persistent tooltip placement, I will keep the current version which is less expansive.

@mistic100 mistic100 closed this May 16, 2024
@HapDragon
Copy link
Author

According to the linked article, the correct computation is

      // distance between points
        const Δφ = φ2 - φ1;
        const Δλ = λ2 - λ1;
        const a = Math.sin(Δφ/2) * Math.sin(Δφ/2)
            + Math.cos(φ1) * Math.cos(φ2) * Math.sin(Δλ/2) * Math.sin(Δλ/2);
        const δ = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a));

no idea where your version come from

however I compared the results :

  • current: [-1.877653919666705,-0.38152789807555176]
  • new: [-1.877661200390654,-0.38152577113488884]

it only differs by 0.00001 rads

given is only used to comput the middle point of polylines which is only used for persistent tooltip placement, I will keep the current version which is less expansive.

Hello, mistic100, the reason I find something maybe wrong is when I try to compute the midpoint of two point: such as :
poi1 :[longitude,latitude]: [6.160393754326874, -0.024855334829736897]
poi2 :[longitude,latitude] : [0.058584340850442264, 0.028657665309549385]
then the function: greatArcIntermediaryPoint(pos1,pos2,0.5) will give a mid point not in the line between poi1 & poi2, in fact it will be on the other side of the sphere.

So I look about the definition of this function, and the article link before the function: http://www.movable-type.co.uk/scripts/latlong.html, and find the paragraph below:
image
According to this, maybe is the problem, so I modify the code, after test, it shows, the problem above is removed.

@mistic100
Copy link
Owner

Ok then it is probably an error in the "greatArcDistance" function which does not handle well crossing 0/2Pi

@mistic100
Copy link
Owner

So I just tested it

var p1 = [6.160393754326874, -0.024855334829736897];
var p2 = [0.058584340850442264, 0.028657665309549385];

greatArcIntermediaryPoint(p1, p2, 0.5)
//  [-0.032108232961702045, 0.0019090099811879602]

this seems correct, the midpoint is not at the other side of the sphere

And when used to display permanent tooltips, it is correctly placed
127 0 0 1_8080_plugin-markers html

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants