Is a point inside or outside a polygon which is on the surface of a globe

纵然是瞬间 提交于 2019-12-03 12:13:44

In fact the normal ray tracing and winding rule approaches work just fine on the surface of a sphere, with a little adjustment.

On the surface of a sphere a 'straight line' is a great circle and distances are measured in angular units rather than metres or inches. To draw a ray from an arbitrary point on the surface of the sphere simply form a great circle through that arbitrary point and any other point on the surface of the sphere. To keep the maths clean choose a second point about pi/2 away from the point whose location you are testing. Apply the usual even-odd rule to the great circle and your test polygon.

The winding rule also translates directly from straight lines in the plane to (segments of) great circles on a sphere.

All you need now are Java implementations of basic spherical geometry operations. I don't have any recommendations on that front, but I guess the Internet will help. For the maths start with Mathworld.

Another approach would be to project your points and polygons from the surface of the sphere to the plane -- which is what map projections do -- the topological relationship of insideness will not be affected by such a transformation.

Oh, and you'll have to decide what to do if your polygon describes a great circle

Use planes instead of rays. A "line" on the surface of a sphere defined by two points is an arc of a great circle (circle whose center is the center of the sphere) and is also contained in a plane that contains those two points and the center of the sphere.

Test whether the point is "greater" or "less" than the corresponding plane for each edge of the "polygon" to determine which side of the "line" it is on.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!