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

• Jun 21st 2008, 03:40 AM
zeeshanzia84
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.

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

Can any one tell me how to do this?

• Jun 21st 2008, 07:18 AM
TKHunny
Are these spheres centered at the Origin? Distance formula is sufficient.

If not, then find the center of the ABC sphere and it's the same problem.
• Jun 21st 2008, 07:20 AM
zeeshanzia84

Yes, the sphere is centered at the origin.

Can you please explain, how the distance formula maybe used to find this out?
• Jun 21st 2008, 07:24 PM
TKHunny
In Rectangular Coordiantes, the point's address, (x,y,z) are easily used to calculate the distance - or in this case the square fo the distance will be fine - assuming the UNIT sphere is the only measure fo concern.

Distance From Origin = $\sqrt{x^{2}+y^{2}+z^{2}}$

If that's Greater than 1, it's outside.

I think your only real problem is likely to be precision. Is 1.00000000001 Outside or ON the Unit sphere? You WILL have to make up your mind.
• Jun 22nd 2008, 12:54 AM
zeeshanzia84
Thanks for the reply. But, you didn't understand the problem at all. All four point lie on the same unit sphere center at the origin. So, ofcourse their distances from the origin will be 1 !

I want to decide whether X lies within the area that is bounded by A,B and C.
• Jun 22nd 2008, 02:01 PM
TKHunny
Well, it wasn't all that bad. I seem to have missed this section "which are also on the unit sphere". It is hard to judge the level of the question when no work is shown.

Find the three planes: OAB, OBC, OCA.
• Jun 22nd 2008, 02:03 PM
zeeshanzia84
Thanks a lot. I get it now!
• Jun 23rd 2008, 09:24 AM
egvega
I'm new in sphere math world and i have the same problem.
Perhaps I'm wrong or perhaps I don't know how to implement the method of the planes you have decribed previously, but I think you are missing a little surface where you point may lye. If the region enclosed by points A B C is really a triangle (triangulated sphere) there will be no problem(I don't know how to calculate but I guess there will no information missing). But if points do not form a triangle but something like this:

B
A )
C

The plane OBC will leave outside the region |).

Correct me if i'm wrong
• Jun 23rd 2008, 09:28 AM
zeeshanzia84
Yes egvega you are right. And this was the whole problem. Otherwise, finding a point exists within a triangle is not difficult.

The region bounded by the three points will NOT be (and cannot be) triangular on the sphere's surface! Still, the method described by TKHUNNY should work.
• Jun 23rd 2008, 09:39 AM
egvega
You're lucky if it's useful but i'm still trying to solve the problem. The case is that I do care about the region left outside the planes.
I found a way to know where the point is using sphere coordinates theta and phi but when the sphere rotate and the point is fixed, I don't know how to calculate the new region(i give numbers to them) enclosed by other 3 or 4 points where the point lyes. So I was looking for some general algorithm that i can apply no matter which rotation and how many of them I perform on the sphere.
• Jun 23rd 2008, 09:40 AM
zeeshanzia84
Their won't be ANY region left outside.
• Jun 23rd 2008, 09:48 AM
egvega
If you have the point A on one pole and both,B and C, on, let's say, 45 degrees of latitude. The line conecting B and C will be an arc. So the plane OBC will leave some of the region outside. Check it with a ball, I have one on my hands right now
• Jun 23rd 2008, 10:02 AM
zeeshanzia84
Yes. Now imagine a plane containing the points O,A,B (this plane is perpendicular to the curvature) ....now take another plane O,A,C and another plane O,B,C ..

Now we just need to find whether X lies 'IN BETWEEN' these three planes.
• Jun 23rd 2008, 10:43 AM
TKHunny
The three cutting planes must be distinct. If you get only 2 planes, B is on OAC, for example, the problem of containment makes no sense. A, B, and C must be NONcolinear - in a Great Circle sense.