【问题标题】:How to plot points on several concentric circles in sequence?如何在多个同心圆上依次绘制点?
【发布时间】:2017-06-18 00:28:23
【问题描述】:

我想在几个同心圆上画几个点,就像这样:

不同圆上的点数相同,待定。半径之差相同。

但我面临的问题是,如果我想使用for 函数,我定义了i = 1:total number of points。我不知道如何选择正确的角度值。谁能帮帮我?

这是我写的代码:

R_steplength = 1; %difference of radius
angle_point = 20; %total number of points on one circle
max_R = 4; %outer radius of circle
central_x = 1; % origin of concentric circle
central_y = 1;

total_circle_points = (max_R/R_steplength) * angle_point; %calculate total
points
fin_x= zeros(1, total_circle_points); %define output points position
fin_y = zeros(1, total_circle_points);

for i = 1:total_circle_points
    for j = 1:angle_point
        if rem(i+1, 20)~= 1
            k = floor(i/20);
            angles = linspace(0,2*pi,angle_point);
            fin_x(i) = R_steplength*(k+1)*cos(angles(j))+central_x;
            fin_y(i)= R_steplength*(k+1)*sin(angles(j))+central_y;
        else
            fin_x(i) = central_x + R_steplength*(k+2);
            fin_y(i) = central_y + R_steplength*(k+2);
        end
        plot(fin_x(:),fin_y(:),'ro')
    end

end

【问题讨论】:

    标签: matlab plot geometry matlab-figure angle


    【解决方案1】:

    您可以为此使用polarplot:

    ax = polaraxes; % create polar axes
    % calculate all points locations:
    [angles,rad] = meshgrid(0:angle_point:360,1:R_steplength:max_R);
    polarplot(ax,deg2rad(angles),rad,'r.') % plot all the points
    ax.GridColor = 'k'; % set grid color to black
    ax.GridAlpha = 1;
    ax.ThetaAxis.TickValues = 10:20:360; % set radius grid between the points
    ax.RAxis.TickValues = 1.5:R_steplength:(max_R+0.5); % set circles between the points
    ax.RAxis.Limits = [0 max_R+0.5]; % show the outer circle
    

    这里我使用坐标轴网格来绘制圆圈。如果不需要,你可以写:

    [angles,rad] = meshgrid(0:angle_point:360,1:R_steplength:max_R);
    polarplot(ax,deg2rad(angles),rad,'r.') % plot all the points
    

    【讨论】:

      猜你喜欢
      • 2012-04-27
      • 2011-05-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-01-31
      • 2014-01-12
      • 2021-01-30
      • 1970-01-01
      相关资源
      最近更新 更多