Locations of the Intersections between the circles
3 ビュー (過去 30 日間)
古いコメントを表示
I have plotted many circles under two sets;
N=viscircles(xya,repmat(1000,size(xya,1),1),'color','b'); hold on
W=viscircles(dya,repmat(1000,size(dya,1),1,'color','r')
I want to find the locations of the intersections between the circles in N with circles in W.
0 件のコメント
採用された回答
Walter Roberson
2021 年 9 月 6 日
The output of viscircles is a hggroup object. It has two children, accessible with the Children property; each child is a Line object.
The first of the children by default has Linewidth 3, and the second of the children by default has Linewidth 2. The coordinates associated with the two children are the same: what is happening is that two lines are being created, one thinnner than the other and on top of the second thicker one. The fraction of the thicker one that shows up outside where the thinner one is drawn, is acting as the edge color. That is, instead of drawing an inner edge, a center, and an outer edge, it draws a thinner circle on top of a thicker circle knowing that the edges of the thicker circle will peek out.
You can extract the coordinates associated with the lines, so for example,
N.Children(1).XData %and YData
You might have noticed that the situation does not describe having one (or two) circles for each circle that is drawn. Instead, the XData and YData describe all of the circles together, with NaN between the independent circles.
Now, you could extract the coordinates from the XData and break it up at the NaN and find the intersections.... but it is considerably easier to ignore the return values from viscircle() and instead go back to the coordinates you pass in, xya, dya, and the information about the radii. Then you have a more straight-forward "intersection of circles" situation
xya_radius = 1000; dya_radius = 1000;
dists = pdist2(xya, dya) - repmat(xya_radius,size(xya,1),1) - repmat(dya_radius,1, size(dya,1));
Now if dists(J,K) is negative then xya(J,:) intersects with dya(K,:). Take triu() or triu() to avoid processing the same pair twice, and proceed to calculate the intersection points (though be careful about cases the circles just touch.) https://math.stackexchange.com/questions/256100/how-can-i-find-the-points-at-which-two-circles-intersect
13 件のコメント
Walter Roberson
2021 年 9 月 12 日
load xya
load dya
xya_radius = 1000; dya_radius = 1000;
all_d = pdist2(xya, dya);
dists2 = all_d - repmat(xya_radius,size(xya,1),1) - repmat(dya_radius,1, size(dya,1));
mask = (dists2 <= 0);
ind = find(mask);
[idx_x, idx_d] = ind2sub(size(mask), ind);
d = all_d(ind);
sel_xya = xya(idx_x,:);
sel_dya = dya(idx_d,:);
Afterwards:
sel_xya and sel_dya are matrices containing information only about circles that intersect. The information is in corresponding pairs: sel_xya(K,:) intersects with sel_dya(K,:) so you can proceed by rows. d(K) is the distance between the centers sel_xya(K,:) and sel_dya(K,:)
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Line Plots についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!