MATLAB: Distance between a point and the intersection of two spheres

intersectionspheresurface

Hello,
Im trying to filter a sampled 3D human body signal. In sumary thanks to a motion capture system I get the coordinates of the shoulder (A) elbow (B) and wrist (C). the problem is that the distances mesured between AB (Humerus) and BC (Forearm) are not constant. To solve this I'm using the A and C samples as true and relocate the elbow. My idea is to see the points on a sphere of radius R1 (known humerus length) on the shoulder and R2 (known forearm length) on the wrist intersect. This intersection of the two spheres gives a circunference of possible possitions of the elbow. The point of this circunference which is closer to the sample B would be the true position of the elbow.
I've gotten to see the intersection petween both spheres but i couldn't get the points that create it. if anyone could help me it would be amazing.
Thanks in advance.
H=1.80;
humerus=0.179*H;
forearm=0.151*H;
theta=0:pi/80:2*pi;
shi=0:pi/80:pi;
r1=humerus;
c1=[0.2530 2.0740 0.2370];
[THETA, SHI]=meshgrid(theta,shi);
x1=c1(1)+r1*sin(SHI).*cos(THETA);
y1=c1(2)+r1*sin(SHI).*sin(THETA);
z1=c1(3)+r1*cos(SHI);
surf1=surf(x1,y1,z1);
r2=forearm;
c2=[0.2820 2.0920 -0.2870];
x2=c2(1)+r2*sin(SHI).*cos(THETA);
y2=c2(2)+r2*sin(SHI).*sin(THETA);
z2=c2(3)+r2*cos(SHI);
surf2=surf(x2,y2,z2);

Best Answer

This is confusing, possibly because of how you are trying to solve it. I think you are working too hard.
The intersection between two spheres is a circle. Unless you are just trying to plot the spheres, there is no reason to generate them completely. Just find the equation of the circle. MAKE THINGS SIMPLE. Don't overly complicate them.
H=1.80;
humerus=0.179*H;
forearm=0.151*H;
r1=humerus;
c1=[0.2530 2.0740 0.2370];
r2=forearm;
c2=[0.2820 2.0920 -0.2870];
I presume that c1 is the center of sphere 1, and r1 the corresponding radius. Likewise, c2 and r2 are the center and radius of the second sphere.
First, do the spheres intersect? That is easy. I'll call D the distance between centers of the spheres, What mattes is the sum of the sphere radii.
D = norm(c1 - c2)
D =
0.52511
r1 + r2
ans =
0.594
(r1 + r2) > D
ans =
logical
1
If that sum exceeds the distance between spheres, then there is an intersection. If the sum of radii is EXACTLY equal to the distance between spheres, then the two spheres touch at a single point.
We also need to consider the case where one sphere lies entirely inside the other? How can that happen? For that to happen, the radius of the larger sphere must be at least as large as the sum of the distance between spheres, and the SMALLER radius.
max(r1,r2) >= (D + min(r1+r2))
ans =
logical
0
Had that been true, then one sphere would live entirely insode the other.
Given ll that, what is the equation of the circle of intersection? Also easy enough.
The center of that circle must lie on the line segment drawn between the spheres. How far? Assume the distance of the center of the circle along that line segment is d1 from the center of sphere 1. Then a little algebra tells me that
d1 = 1/2*(D + (r1^2 - r2^2)/D)
d1 =
0.29106
So, we now that the circle has center at a distance of 0.2916 units along the line segment, starting at the point c1.
circlecenter = c1 + d1*(c2 - c1)/norm(c2 - c1)
circlecenter =
0.26907 2.084 -0.053446
The radius of the circle of intersection easy, it just comes from the Pythagorean theorem.
circleradius = sqrt(r1^2 - d1^2)
circleradius =
0.13819
What else do you need to compute? The circle lives in the plane perpendicular to that line connecting the two sphere centers.
It is all just basic geometry, with an application or two of the Pythagorean theorem.