# Thread: Checking for a point inside a region of a spherical surface

1. ## Checking for a point inside a region of a spherical surface

Hi everybody,

I am working on a 3D Morphing algorithm.

I have a point X on lying on a unit sphere in the spherical coordinate system. I have three other points A,B, and C which are also on the unit sphere. The sphere is centered at the origin.

I need to find out whether X lies on the spherical 'triangular' area enclosed by A,B, and C or not.

Can any one tell me how to do this?

2. I'm thinking you could maybe make barycentric coordinates work for you, since the surface of a sphere is a 2D surface -- not exactly a plane, but you should be able to deal with just longitude and latitude. There's a system to solve, and if any of your coordinates are less than zero or bigger than one, you're outside the triangle. My handout says that the system is equation 5.58 in Lengyel's book, but I don't know if I have a copy here.

EDIT: If p0, p1, and p2 are your triangle, and p is your other point, then: define q1=p1-p0 and q2=p2-p0 and r=p-p0. Solve the system
(q1*q1)w1 + (q1*q2)w2 = (q1*r)
(q2*q1)w1 + (q2*q2)w2 = (q2*r)
for w1 and w2 (with * meaning dot product), and then w0 = 1 - w1 - w2. The w's are your barycentric coordinates.

3. Thanks a lot for the reply.

So, you are saying that I should represent the points P1, P2, and P3 in Latitude and Longitude form...and this system will still work?

How will I take the dot product in that case?

Again, thanks a whole lot.

4. I'm thinking that latitude and longitude should work as a map from surface-of-sphere to Cartesian flat-piece-of-paper (just be sure that your triangle doesn't cross the "international date line" at the edges). It's not going to keep area or distance, obviously, but it will keep inside/outside.

Dot products are dot products (x*x+y*y).

5. I'm always against translating coordinate systems in order to solve a problem
This is mainly because, if a coordinate system exists it will be able to handle any problem that results from the planes it handles.

But, I may be wrong on those occasions where a translation results in faster performance. Testing would dictate. However, for a first approach I feel the solution should lie within the adopted coordinate system and only then, if performance is not acceptable - and formulae simplification proved still inadequate - should we look into another system.

I work mostly in 2D, I have very little knowledge of 3D formulas and am even nowhere an expert in 2D spaces. However, I feel this will help.