Test to know if a vector is inside a spherical triangle

1.1k Views Asked by At

Given a spherical triangle defined by $3$ unit vectors on a sphere, how can we test if a vector is contained inside the spherical triangle?

1

There are 1 best solutions below

1
On

To test for containment, treat each edge of the triangle as a plane dividing the sphere. The vector is inside the triangle if it is in front of each of those edge planes. To test whether your vector is in front of a plane you just need the normal for that plane.

Calculate the normals for each plane by taking the cross product of each pair of vertices

n0 = v0 × v1
n1 = v1 × v2
n2 = v2 × v0

Once you have the edge normals, just test your vector to see if it's in front of all planes by using dot products

contained = (v • n0 > 0) && (v • n1 > 0) && (v • n2 > 0)

You may need to reverse the cross products for handedness of your coordinates and the ordering of your triangle's vertices.

This should work for any convex shape.