ring (annulis) patch?
Ältere Kommentare anzeigen
Dear friends,
How do I make a 2D ring (annulus) patch? Is it possible to make it as a single patch with a single object handle?
I want plot several 2D objects in a figure. The objects behind the ring should be visible trough the hole, and I want to control the properties of the ring, e.g. with respect to transperancy, color and line style.
Sincerely, Peter.
Akzeptierte Antwort
Weitere Antworten (2)
Matt Tearle
am 20 Mär. 2011
How's this? The patch is a single object, but you have to add the edge lines separately in this approach (otherwise you see the "branch cut" in the annulus).
% Make a plot to add the ring to
x = rand(100,1);
y = rand(100,1);
plot(x,y,'o')
% Make inner and outer boundaries
t = linspace(0,2*pi);
rin = 0.1;
rout = 0.25;
xin = 0.5 + rin*cos(t);
xout = 0.5 + rout*cos(t);
yin = 0.5 + rin*sin(t);
yout = 0.5 + rout*sin(t);
% Make patch
hp = patch([xout,xin],[yout,yin],'g','linestyle','none','facealpha',0.25);
hl1 = line(xin,yin,'color','k');
hl2 = line(xout,yout,'color','k');
6 Kommentare
Peter
am 20 Mär. 2011
Walter Roberson
am 20 Mär. 2011
Try putting a NaN between xout and xin, and between yout and yin.
Peter
am 20 Mär. 2011
Walter Roberson
am 21 Mär. 2011
I suspect this is due to the face color interpolation method that is set, especially with the leading nan (which you do not need, but a trailing nan might not hurt.) I cannot test out my speculations at the moment as I do not have graphic access right now.
Matt Tearle
am 21 Mär. 2011
Yes, I thought of trying it with NaN, but that seems to confuse patch -- I think it's unable to work out where the "inside" of the region is. But I feel like a total idiot for not using the same trick for the boundary line.
Anyway, Peter, what's still missing/lacking from this approach? What do you mean by "pure hollow patches"?
Peter
am 21 Mär. 2011
Sean de Wolski
am 19 Mär. 2011
0 Stimmen
2d or 3d?
For the 2d case just subtract circles. Learn how to make circles here: http://matlab.wikia.com/wiki/FAQ#How_do_I_create_a_circle.3F
You could use the same logic for the 3d "donut" using a formula found on wikipedia.
1 Kommentar
Peter
am 19 Mär. 2011
Kategorien
Mehr zu Graphics Performance finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!