【问题标题】:Plotting multiple circles绘制多个圆
【发布时间】:2016-08-14 14:10:54
【问题描述】:

我想绘制多个圆,中心为之前已经确定的质心。

所以我有这段代码,它使用质心作为圆的中心,但我收到错误:“错误使用 + 矩阵尺寸必须一致。”

r = 4;
cen_x = centroid(:,1);
cen_y = centroid(:,2);
th = 0:pi/50:2*pi;
xunit = r * cos(th) + cen_x;
yunit = r * sin(th) + cen_y;
hold on
h = plot(xunit, yunit);

有什么帮助吗?

【问题讨论】:

    标签: matlab plot geometry figure centroid


    【解决方案1】:

    您正在尝试将cos(th)cen_x 添加在一起,但它们的尺寸不匹配。您将需要使用 bsxfun 以便正确广播维度。

    xunit = bsxfun(@plus, cen_x, r * cos(th)).';   
    yunit = bsxfun(@plus, cen_y, r * sin(th)).';
    
    plot(xunit, yunit)
    

    您也可以使用rectangle 为您绘制圆圈。你也可以指定FaceColor来填写。

    positions = [centroid - (r/2), r + zeros(size(centroid))];
    
    for k = 1:size(positions, 1)
        rectangle('Position', positions(k,:), 'Curvature', [1 1], 'FaceColor', 'r');
    end
    

    【讨论】:

    • 做得很好。我很好奇你是否可以使用imfill 函数来填充这些圆圈?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-07-20
    • 1970-01-01
    • 2015-03-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多