minimum distance to the center of a sphere using matlab
Given 2 points A开发者_如何学JAVA and B belonging to a sphere with a given Radius R. I want to find the sphere whose center has the minimum distance to a given point G.
Thanks
The centers of a sphere defined by two points and a radius is a circle. You can connect C (the center of the circle) and G and create a 90° projection on the circle plane. The minimum distance is where the projection intersects the circle tangent by 90°. There are two solutions. You have to take the smaller one.
The point C you want is in the plane that contains A, B, and G. You compute
AG = G - A;
BG = G - B;
N = cross(AG, BG);
N = N / norm( N ); % the normal to the plane
Now you solve for C in this plane. Three equations:
dot((C-G), N)=0;
sqrt(sum(A-C).^2) = R;
sqrt(sum(B-C).^2) = R;
Three unknowns are the three elements of C. You end up with two solutions, so compute the distance to G and pick the closer one.
精彩评论