简体   繁体   English

圆角矩形坐标表示

[英]Rounded corner rectangle coordinate representation

Simple rounded corner rectangle code in Matlab can be written as follows. Matlab中的简单圆角矩形代码可以编写如下。

rectangle('Position',[0,-1.37/2,3.75,1.37],...
      'Curvature',[1],...
     'LineWidth',1,'LineStyle','-')
daspect([1,1,1])

How to get the x and y coordinates arrays of this figure? 如何获得该图的x和y坐标数组?

To get the axes units boundaries, do: 要获取轴单位边界,请执行以下操作:

axisUnits = axis(axesHandle) % axesHandle could be gca

axisUnits will be an four elements array, with the following syntax: [xlowlim xhighlim ylowlim yhighlim] , it will also contain the zlow and zhigh for 3-D plots. axisUnits将是一个具有以下语法的四元素数组: [xlowlim xhighlim ylowlim yhighlim] ,它还将包含3-D图的zlow和zhigh。

But I think that is not what you need to know. 但是我认为这不是您需要知道的。 Checking the matlab documentation for the rectangle properties , we find: 查看matlab文档中的矩形属性 ,我们发现:

Position four-element vector [x,y,width,height] 位置四元素向量[x,y,width,height]

Location and size of rectangle. 矩形的位置和大小。 Specifies the location and size of the rectangle in the data units of the axes. 以轴的数据单位指定矩形的位置和大小。 The point defined by x, y specifies one corner of the rectangle, and width and height define the size in units along the x- and y-axes respectively. x,y定义的点指定矩形的一个角,宽度和高度分别定义沿x轴和y轴的大小。

It is also documented on the rectangle documentation : 它也记录在矩形文档中

rectangle('Position',[x,y,w,h]) draws the rectangle from the point x,y and having a width of w and a height of h. rectangular('Position',[x,y,w,h])从点x,y绘制矩形,其宽度为w,高度为h。 Specify values in axes data units . 轴数据单位指定值。

See if this illustrate what you want. 看看这是否说明您想要什么。 You have an x axis that goes from −100 to 100 and y axis that goes from 5 to 15. Suppose you want to put a rectangle from −30 to −20 in x and 8 to 10 in y. 您有一个x轴,该轴从−100到100,y轴从5到15。假设您要在x的范围内放置一个介于−30到−20之间的矩形,在y的范围内放置一个介于8至10的矩形。

rectangle('Position',[-30,8,10,2]);

As explained by the comments there appears to be no direct way to query the figure created by rectangle and extract x/y coordinates. 正如评论所解释的那样,似乎没有直接的方法来查询由rectangle创建的图形并提取x / y坐标。 On the other hand, I can think of two simple strategies to arrive at coordinates that will closely reproduce the curve generated with rectangle: 另一方面,我可以想到两种简单的策略来获得坐标,这些坐标将紧密地再现由矩形生成的曲线:

(1) Save the figure as an image (say .png) and process the image to extract points corresponding to the curve. (1)将图形另存为图像(例如.png),并处理图像以提取与曲线相对应的点。 Some degree of massaging is necessary but this is relatively straightforward if blunt and I expect the code to be somewhat slow at execution compared to getting data from an axes object. 一定程度的按摩是必要的,但是如果直率的话,这相对简单,我希望代码与从轴对象获取数据相比执行起来会有些慢。

(2) Write your own code to draw a rectangle with curved edges. (2)编写自己的代码以绘制具有弯曲边缘的矩形。 While recreating precisely what matlab draws may not be so simple, you may be satisfied with your own version. 精确地重新创建matlab绘制的内容可能并不那么简单,但您可能会对自己的版本感到满意。

Whether you choose one of these approaches boils down to (a) what speed of execution you consider acceptable (b) how closely you need to replicate what rectangle draws on screen (c) whether you have image processing routines, say for reading an image file. 是否选择这些方法之一归结为(a)您认为可接受的执行速度(b)您需要多近地复制屏幕上绘制的rectangle (c)是否具有图像处理例程,例如读取图像文件。

Edit 编辑

If you have the image processing toolbox you can arrive at a set of points representing the rectangle as follows: 如果有图像处理工具箱,则可以按如下所示到达代表矩形的一组点:

h=rectangle('Position',[0,-1.37/2,3.75,1.37],...
      'Curvature',[1],...
     'LineWidth',1,'LineStyle','-')
daspect([1,1,1])
axis off
saveas(gca,'test.png');
im = imread('test.png');
im = rgb2gray(im);
figure, imshow(im)

Note that you will still need to apply a threshold to pick the relevant points from the image and then transform the coordinate system and rearrange the points in order to display properly as a connected set. 请注意,您仍然需要应用阈值以从图像中选择相关点,然后变换坐标系并重新排列这些点,以便正确显示为已连接的集。 You'll probably also want to tinker with resolution of the initial image file or apply image processing functions to get a smooth curve. 您可能还需要调整初始图像文件的分辨率,或者应用图像处理功能以获得平滑的曲线。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM