Filter löschen
Filter löschen

Locations of the Intersections between the circles

4 Ansichten (letzte 30 Tage)
Salem
Salem am 6 Sep. 2021
Kommentiert: Salem am 13 Sep. 2021
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.

Akzeptierte Antwort

Walter Roberson
Walter Roberson am 6 Sep. 2021
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 Kommentare
Walter Roberson
Walter Roberson am 12 Sep. 2021
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,:)
Salem
Salem am 13 Sep. 2021
Thank you so much, I really appreciate it.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Line Plots finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by