How to plot only selected spheres?
5 ビュー (過去 30 日間)
古いコメントを表示
I have plotted spheres in space from known coordinates and radius. All the spheres are randomly distributed in space. I want to plot only those spheres which are intersecting with each other from top to bottom along the z-axis. I dont want to plot the rest of spheres. Is there any way to do it? I am doing it manually which is wasting a lot of my time. I see only for those spheres which are in continuity and deleting the rest spheres manually which is quite frustrating. Your help and suggestions would be highly appreciated.
0 件のコメント
回答 (1 件)
Image Analyst
2016 年 2 月 4 日
For each sphere, compute the distance of it's center to the centers of all the other spheres. If the distance is less than the sum or their two radii, then those two spheres overlap, and record/log that pair of spheres. Then, once all overlapping pairs have been identified, clear the axes or use a new one and plot only those spheres that had overlap. Code should be straightfoward. Let me know if you can't figure it out. Here's a start, assuming you have an array xyzr with one row for every sphere
numSpheres = size(xyzr, 1);
for k = 1 : numSpheres
distances = sqrt((xyzr(:, 1) - xyzr(k, 1))^2 + (xyzr(:, 2) - xyzr(k, 2))^2 + (xyzr(:, 3) - xyzr(k, 3))^2)
sumOfRadii = xyzr(k, 4) + xyzr(:, 4);
overlaps = distances < sumOfRadii;
indexes = find(................
end
% etc.
That should be a good start. See if you can finish it.
2 件のコメント
Image Analyst
2016 年 2 月 4 日
Each sphere has an index - some kind of ID number to identify it. Why didn't you just keep track of those that had the distance less than the sum of the radii?
overlaps = distances < sumOfRadii;
indexes = find(overlaps); % Keep track of indexes that overlap the k'th sphere.
参考
カテゴリ
Help Center および File Exchange で Surface and Mesh Plots についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!