[英]Drawing a circle using a PointF as its center c#
I was searching for this but I couldnt find anything. 我正在寻找这个,但找不到任何东西。 The idea is I have a PointF like (52.66, 60.11) and I want to draw an empty circle with this PointF as its center.
我的想法是我有一个PointF像(52.66,60.11),我想绘制一个以PointF为中心的空圆。 I was trying to do with DrawEllipse but it does not care about the center!
我试图使用DrawEllipse,但它不在乎中心! it is just a rectangle...I think some kind of conversion formula should be used?
它只是一个矩形...我认为应该使用某种转换公式?
You can compute the coordinates of the rectangle from the center and radius: 您可以根据中心和半径计算矩形的坐标:
float x = center.X - radius;
float y = center.Y - radius;
float width = 2 * radius;
float height = 2 * radius;
graphics.DrawEllipse(pen, x, y, width, height);
out of mind: 心不烦:
RectangleF circle2Rect(Point midPoint, float radius) {
return new RectangleF(midPoint.X-radius,
midPoint.Y-radius,
radius*2,
radius*2);
}
(This is not tested) Use it to convert the parameter of the circle to a rectangle for drawing. (未经测试)使用它可以将圆的参数转换为矩形以进行绘制。
如果您绘制具有相同高度和宽度的椭圆,则会得到一个圆,如果您需要知道绘制圆的正方形的上下左右坐标,则知道中间点(中心)是相当平庸的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.