chrisveness / geodesy

Libraries of geodesy functions implemented in JavaScript
http://www.movable-type.co.uk/scripts/geodesy-library.html
MIT License
1.17k stars 203 forks source link

MinimumDistanceToLineSegment( Start, Stop, Point ); #110

Closed SkybuckFlying closed 1 year ago

SkybuckFlying commented 1 year ago

In case there is no other function in this library then please try and implement a function which behaves like CrossTrackDistanceAt but which respects the line segment concept.

Prototype/function header could look like:

MinimumDistanceToLineSegment( Start, Stop, Point );

Where Start,Stop,Point are either Vector3D/X,Y,Z points on a sphere, or lat/long. Preferably the first one, or both versions be nice too.

So the distance should be large when the point is far away from Start and Stop...

Perhaps this function should get an extra parameter... like MaximumDistance....

So that if the minimum distance exceeds this threshold it will return false or so... otherwise if it is within this range... true...

Maybe isWithinExtent is for ment for this, have not tried it yet, but will try so later/another time/another day... don't know when yet, maybe tomorrow if I feel like it and up to the challenge lol. My time is not infinite... and neither is my energy and/or motivation lol...

Thanks so far ! ;)

SkybuckFlying commented 1 year ago

I think the library already has functions to do this, I think this might work and do what I want:

Another idea could be to use:

nearestPointOnSegment to compute the point which is closest on that segment...

then compute DistanceTo(closestPointOnSegment)

I think this should work for what I want.

if this distance is within wanted range then render pixel otherwise not ! ;)

I will try this out soon.... closing this for now...