Hello, I saw a small item on the
TODO list (distance from point to
an ellipsoid) and I tried to solve
the problem. I think the code will
work (less than 20 lines), but I'm
not sure how to contribute. The
code is here if anyone would like
to see/commit it:
http://www.log2.net/distance.h-contrib.txt
Celestia is great! -cpb
Distance to ellipsoid - will this work?
-
- Site Admin
- Posts: 4211
- Joined: 28.01.2002
- With us: 22 years 9 months
- Location: Seattle, Washington, USA
That's for the code Chris. Unfortunately, it's not quite correct . . . Your code returns the distance from a point to an ellipsoid along the line from the point to the center of the ellipsoid. This is certainly better than just returning zero, but it won't give the right answer unless the ellipsoid happens to be a sphere. The shortest distance from a point to an ellipsoid is always on a line normal to the surface of the ellipsoid (which for a sphere happens to be any line which intersects the center.) To compute it generally, you need to find the root of a sixth degree polynomial. This by itself isn't so difficult, but there are degeneracies for points that lie near the ellipsoid axes that require special handling.
--Chris
--Chris
chris,
Out of curiousity, do you need the full generality of ellipsoids or would the closest distance to a spheroid suffice? In the later case, the roots are closed form. The extra symmetry reduces the problem from a 6th order to a 4th order polynomial, just as the spherical case reduces to a 2nd order polynomial.
Walton
Out of curiousity, do you need the full generality of ellipsoids or would the closest distance to a spheroid suffice? In the later case, the roots are closed form. The extra symmetry reduces the problem from a 6th order to a 4th order polynomial, just as the spherical case reduces to a 2nd order polynomial.
Walton
Chris,
I found the todo list and as I suspected the full generality of an ellipsoid is not required. Due to symmetry, the closest location on the surface must lie in the plane shared by the point and the oblate axis; and the intersection of the spheroid and this plane is an ellipse. Therefore, it is sufficient only to calculate the distance between a point and an ellipse.
A web search turns up the following theory
http://www.magic-software.com/Documenta ... lipse2.pdf
Open sourced sample code:
http://www.magic-software.com/Source/Di ... Vec2Elp2.h
http://www.magic-software.com/Source/Di ... c2Elp2.cpp
Distribution license:
http://www.magic-software.com/License/WildMagic.pdf
cheers,
Walton
I found the todo list and as I suspected the full generality of an ellipsoid is not required. Due to symmetry, the closest location on the surface must lie in the plane shared by the point and the oblate axis; and the intersection of the spheroid and this plane is an ellipse. Therefore, it is sufficient only to calculate the distance between a point and an ellipse.
A web search turns up the following theory
http://www.magic-software.com/Documenta ... lipse2.pdf
Open sourced sample code:
http://www.magic-software.com/Source/Di ... Vec2Elp2.h
http://www.magic-software.com/Source/Di ... c2Elp2.cpp
Distribution license:
http://www.magic-software.com/License/WildMagic.pdf
cheers,
Walton
Kolano,
Unfortunately, you picked a poor example, since it's already possible.
Install one pf Fridger's Gazetteers (a list of the locations of many cities). E.g.
http://www.shatters.net/~t00fri/earth-Gazetteer-intl.ssc.zip
Install one of Thomas Guilpain's geosynchronous satellite Addons. E.g. visit http://www.celestiamotherlode.net/catalog/satellites.html
GoTo NYC
Select the satellite
Observe the distance that Celestia displays in the upper left corner.
Unfortunately, you picked a poor example, since it's already possible.
Install one pf Fridger's Gazetteers (a list of the locations of many cities). E.g.
http://www.shatters.net/~t00fri/earth-Gazetteer-intl.ssc.zip
Install one of Thomas Guilpain's geosynchronous satellite Addons. E.g. visit http://www.celestiamotherlode.net/catalog/satellites.html
GoTo NYC
Select the satellite
Observe the distance that Celestia displays in the upper left corner.
Selden