Sphere Intersection Curve

23 views (last 30 days)
manish sharma
manish sharma on 13 Nov 2011
Answered: nick on 30 Jan 2024
Hi,
I am interested in visualizing (and locating) the points of intersection of three (or four) spheres.
*Region of my interest is the volume (of air or other material of the room) enclosed between intersecting spheres.
**The Center and Radius of both the spheres are known
This problem has me completely stuck.
Thank you.
  2 Comments
Sven
Sven on 13 Nov 2011
This link gives a very thorough mathematical overview of the intersection between spheres.
http://mathworld.wolfram.com/Sphere-SphereIntersection.html
That's a good place to start.
manish sharma
manish sharma on 16 Nov 2011
Thanks Sven!
I know the basics. I have drawn the spheres using:
[x1,y1,z1] = sphere(30);
x1=x1*6.3245;
y1=y1*6.3245;
z1=z1*6.3245;
mesh(x1-5, y1+5, z1) % where (a,b,c) is center of the sphere
hold on
[x2,y2,z2] = sphere(30);
x2=x2*10;
y2=y2*10;
z2=z2*10;
mesh(x2+5, y2+5, z2)
hold on
[x3,y3,z3] = sphere(30);
x3=x3*8.9443;
y3=y3*8.9443;
z3=z3*8.9443;
mesh(x3+5, y3-5, z3)
figure;surface(x1,y1,z1);surface(x2,y2,z2);surface(x3,y3,z3);view(30,30);grid
hold off
From this, I can easily get the image containing the three spheres.
Now, I want to move to next step. That is, plotting the curve enclosed between the intersecting spheres.

Sign in to comment.

Answers (1)

nick
nick on 30 Jan 2024
Hi Manish,
I understand from your query that you are interested in visualizing the points of intersection of three spheres.
You can use MATLAB to find a numerical approximation of the intersection. Below is an example MATLAB script that finds and plots the approximate intersection lines between three spheres:
% Define sphere centers and radii
centers = [-5 5 0; 5 5 0; 5 -5 0];
radii = [6.3245, 10, 8.9443];
% Create a finer grid of points to sample the space
[x, y, z] = meshgrid(linspace(-15, 15, 200), ...
linspace(-15, 15, 200), ...
linspace(-15, 15, 200));
% Initialize logical arrays for sphere inclusion
insideSphere1 = false(size(x));
insideSphere2 = false(size(x));
insideSphere3 = false(size(x));
% Check each point in the grid for inclusion in each sphere
for i = 1:3
r = radii(i);
c = centers(i, :);
% Compute the distance from the current sphere center
distances = sqrt((x - c(1)).^2 + (y - c(2)).^2 + (z - c(3)).^2);
% Points within a tolerance from the sphere surface are considered as intersecting
tolerance = 0.1; % Reduced tolerance for higher accuracy
if i == 1
insideSphere1 = distances < r + tolerance;
elseif i == 2
insideSphere2 = distances < r + tolerance;
else
insideSphere3 = distances < r + tolerance;
end
end
% Find points that lie on the intersection of all three spheres
intersectionPoints = insideSphere1 & insideSphere2 & insideSphere3;
% Extract the intersection points
xi = x(intersectionPoints);
yi = y(intersectionPoints);
zi = z(intersectionPoints);
% Plot the spheres
figure;
hold on;
for i = 1:3
[sx, sy, sz] = sphere(30);
sx = sx * radii(i) + centers(i, 1);
sy = sy * radii(i) + centers(i, 2);
sz = sz * radii(i) + centers(i, 3);
mesh(sx, sy, sz, 'FaceAlpha', 0.3);
end
% Plot the approximate intersection curve
plot3(xi, yi, zi, 'r.', 'MarkerSize', 5);
% Adjust the view
view(30, 30);
axis equal;
grid on;
xlabel('X');
ylabel('Y');
zlabel('Z');
title('Intersection of Three Spheres with High Density');
hold off;
This script uses a brute-force approach to check for points that are close to the surface of all three spheres within a specified tolerance. It's not the most efficient method, but it can give you a visual approximation of the intersection curves as shown:
Hope this helps.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!