I am working on a Python script to:
- Compute the vertex coordinates of a geodesic sphere/icosahedron,
- Project the triangles onto a sphere, then
- Find which spherical triangle contains an arbitrary point.
I would ultimately like to provide my script with a list of sample point coordinates (potentially millions of records), and the script would indicate which triangles contain points. These characters would then be used for presence-absence data in biological studies.
I'm mostly done, but am struggling with Step 3. Is there a fast algorithm to identify whether a point is contained within a spherical equilateral triangle? In two dimensions for general polygons, if a ray extending from the point crosses the polygon's perimeter and odd number of times, it is contained. However, this seems potentially expensive to compute in three dimensions since the perimeter is curved.
It seems like there should be a clever way to exploit the symmetry of spherical equilateral triangles, or the symmetry of the tiling over the surface of the sphere, but I'm just not seeing it. I don't typically work on spherical trigonometry or GIS, so please excuse me if the problem statement is unclear.
Let $A,B,C$ be the vertices of spherical triangle (not necessarily equilateral), and $P$ a given point. I will consider them as 3D vectors. The triple product $(A\times B)\cdot C$ is either positive or negative, depending on the order in which $A,B,C$ go around the triangle. Either way,
On other words, the orientation of the triple of vectors $A,B,C$ should not change if one of three vectors is replaced by $P$.
If you get zero from one of the triple products, the point $P$ lies on the boundary of triangle.