javascript - Projecting a point onto a path -
suppose have ordered array containing points (lat, lon) describing path, , have point (lat, lon) describing current location.
how can project point onto path (and place point in appropriate place in array)?
what tried searching nearest 2 points , assume it's in middle of them. it's guess, fails.
what way of doing this?
i see this:

p0,p1path line segment endpointsppositionq'closest point on line in 3d cartessianqq'corrected spherical projection
so:
- convert points 3d cartessian coordinates
 compute perpendicular distance point , line
q'=p0+(dot(p-p0,p1-p0)*(p1-p0)/(|p-p0|*|p1-p0|))perpendicular_distance = |p-q'|
find segment smallest perpendicular_distance
and use rest of bullets
compute
qif use sphere instead of ellipsoid know radius if not either compute radius algebraically or use average:
r=0.5*(|p0-(0,0,0)|+|p1-(0,0,0)|)assuming
(0,0,0)earth's center. can more precise if weight position:w=|q'-p0|/|p1-p0| r=(1-w)*|p0-(0,0,0)|+w*|p1-(0,0,0)|now correct position of
q'q=q'*r/|q'|set vector
q'qsizerif not obvious enough.|p0-(0,0,0)|=|p0|wanted sure how got ...convert
qcartesian spherical coordinates
[notes]
|a|size of vectoradone like:|a|=sqrt(ax*ax+ay*ay+az*az)dot(a,b)dot product of vectorsa,bdone like:dot(a,b)=(a.b)=ax*bx+ay*by+az*bzif path not complex shaped can use binary search find closest segment. distance comparison not need
sqrt...
Comments
Post a Comment