MATLAB爱好者论坛-LabFans.com

MATLAB爱好者论坛-LabFans.com (https://www.labfans.com/bbs/index.php)
-   资料存档 (https://www.labfans.com/bbs/forumdisplay.php?f=72)
-   -   在MATLAB中放错了圆圈 (https://www.labfans.com/bbs/showthread.php?t=26497)

poster 2019-12-14 20:13

在MATLAB中放错了圆圈
 
我正在尝试在具有给定X,Y坐标和半径的MATLAB中的图像上绘制圆。这是为我绘制多个圆圈的方法的代码夹头-

function circle( Xs, Ys, Rs, LineWidth, LineColor) radius = Rs; centerX = Xs; centerY = Ys; for i=1:length(centerX) rectangle('Position',[centerX(i), centerY(i), radius(i), radius(i)],... 'Curvature',[1,1],... 'LineWidth',LineWidth,... 'LineStyle','-',... 'EdgeColor',LineColor); end end 但是,每当我在图像中看到圆圈时,都会发现圆圈与给定的坐标有一些错位(例如,它们向右/向下移动了一点)。我该如何解决这个问题?



[B]回答:[/B]

您正在绘制的实际上是一个[URL="http://www.mathworks.com/help/techdoc/ref/rectangle.html"]矩形[/URL] 。但是您定义了一个曲率,使其看起来像一个圆。然后,通过带有矩形坐标的边界框定义圆。矩形的位置是左上角(或在常规绘图中是左下角),而您所说的半径实际上是该边界框的宽度和高度。

这就是我的意思:

>> figure, imshow(I) >> rectangle('Position',[100,100,120,120],'Curvature',[1,1]) >> rectangle('Position',[100,100,120,120],'Curvature',[0,0],'EdgeColor','r') >> axis on 此代码将在由左上角的相同矩形坐标定义的相同位置产生一个圆和一个矩形。红色是我正在谈论的边界框。 [IMG]https://i.stack.imgur.com/eFGdh.png[/IMG]

编辑:如果您不想使用矩形函数,则可以执行以下操作:

>> figure,imshow(I) >> hold on >> plot(centerX+radius*sin(0:0.1:2*pi),centerY+radius*cos(0:0.1:2*pi))

[url=https://stackoverflow.com/questions/5207084]更多&回答...[/url]


所有时间均为北京时间。现在的时间是 04:55

Powered by vBulletin
版权所有 ©2000 - 2025,Jelsoft Enterprises Ltd.