Sphere Intersection Curve
23 views (last 30 days)
Show older comments
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
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.
Answers (1)
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.
0 Comments
See Also
Categories
Find more on Surface and Mesh Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!