How to divide plotted circles in a certain number of pieces depending on the radius of the circle
10 次查看(过去 30 天)
显示 更早的评论
I want to seperate circles with different radius into a certain number of equal pieces.
- The radius of the next circle is always double the radius of the current circle.
- All circles have the common coordinates x=0 and y=0. The first circle (radius=1) is only one piece. The second circle (radius=2) is divided in two pieces and so on.
- The pieces are so distributed that the top piece would be dived by a line drawn from the coordinates (0,0) to the coordinates (0,Radius*2*x)
- The radius of the last circle should be adjustable
- The amount of pieces in the last circle should be counted
My current code is not working and I don´t know what to do because it is my first time using MATLAB.
My code is not working as I want but I don't know what's wrong and how I should add the missing operations which are still missing. I would be very thankful if there's someone who wants to help me.
My current code:
function plot_circle(rr,xm,ym,xx,yy,str_)
plot(rr*xx+xm,rr*yy+ym,str_) % first circle
unterteiler = 32; %amount of points which create the different circles
tt = linspace(0,2*pi,unterteiler+1); %divides the circles in several "pieces"
yy = -cos(tt);xx=sin(tt); %calculates the coordinates of the circles
rr=1/pi;
plot_circle(rr,0,rr,xx,yy,'b'); %plots the first circle in blue
hold on
%for k=1:5
for k=1:4
rr=rr*2;
plot_circle(rr,0,rr,xx,yy,'r.'); %plots all nexts circles with red points
faktor=rr/(1/pi) %calculates the current factor of the radius for the current circle
Winkel=(360/faktor)/180*pi %calculates the arc measure of all pieces
koordinatex1=sin(Winkel/2)*rr %calculates the x coordinate for the first piece
koordinatey1=-cos(Winkel/2)*rr %calculates the y coordinate for the first piece
plot(koordinatex1,koordinatey1) %plots the first point
hold on
for m=Winkel:Winkel:360-faktor*Winkel %this should plot the points for all missing pieces; the amount of pieces depends on the factor
koordinatexx=koordinatex1+sin(Winkel*m)
koordinateyy=koordinatey1-cos(Winkel*m)
plot(koordinatexx,koordinateyy,'g')
hold on
end
end
0 个评论
回答(1 个)
Shubham Khatri
2021-2-5
编辑:Shubham Khatri
2021-2-5
Hello,
Please take a look at the following code. You can modify the maximum radius value by changing r_max.The variable r can be used to pull out the number of piece.
r=1;
r_max = 256;
while (r<r_max)
orig_x = 0;
orig_y = 0;
cx = orig_x;
cy = orig_y+r;
numPoints = 256;
theta = linspace(0,2*pi,256);
x_coord = cx+r*cos(theta);
y_coord = cy+r*sin(theta);
X_mat = reshape(x_coord,[],r);
Y_mat = reshape(y_coord,[],r);
plot(X_mat,Y_mat,'Color',rand(1,3));
r = r*2;
hold on
end
hold off
Hope it helps
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Annotations 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!