如何计算圆的直径或半径 [英] How to calculate diameter or radius of the circle
本文介绍了如何计算圆的直径或半径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
if (_shapeChecker.IsCircle(_edgePoint, out _center, out _radius))
{
Rectangle[] _rects = _blobCounter.GetObjectsRectangles();
string _shapeString = "" + _shapeChecker.CheckShapeType(_edgePoint);
Pen _pen = new Pen(Color.Red, ipenWidth);
int _x = (int)_center.X;
int _y = (int)_center.Y;
_g.DrawString(_shapeString, _font, _brush, _x, _y);
_g.DrawEllipse(_pen, (float)(_center.X - _radius),
(float)(_center.Y - _radius),
(float)(_radius * 2),
(float)(_radius * 2));
//size of rectange
foreach (Rectangle rc in _rects)
{
///for debug
//System.Diagnostics.Debug.WriteLine(
// string.Format("Circle size: ({0}, {1})", rc.Width, rc.Height));
iFeatureWidth = rc.Width;
double dis = FindDistance(iFeatureWidth);
//textBox1.Text = dis.ToString("N2");
_g.DrawString(dis.ToString("N2"), _font, _brush, _x, _y + 60);
// textBox1.Text= dis.ToString("N2"), _font, _brush, _x, _y + 60);
// get bounding rectangle of the points list
IntPoint minXY, maxXY;
PointsCloud.GetBoundingRectangle(_edgePoint, out minXY, out maxXY);
// get cloud's size
IntPoint cloudSize = maxXY - minXY;
// calculate center point
DoublePoint center = minXY + (DoublePoint)cloudSize / 2;
// calculate radius
float radius = ((float)cloudSize.X + cloudSize.Y) / 4;
textBox2.Text = Convert.ToString(radius);
textBox3.Text = dis.ToString();
}
}
我是什么尝试过:
What I have tried:
float radius = ((float)cloudSize.X + cloudSize.Y) / 4;
textBox2.Text = Convert.ToString(radius);
textBox3.Text = dis.ToString();
推荐答案
你以一种猜测工作的方式提出问题。事实证明我很无聊所以我会猜测。
你发现你认为或确定的某个边界是一个圆圈。然后你说:圆的半径是两边的一半。哪个是合乎逻辑的。
你为什么总和X和Y然后除以4呢?它完全没有任何意义,因为它只有在矩形是一个sqaure(X = Y)时才能工作,但在这种情况下只需选择一个并除以2,为什么要费心呢?
这里的主要逻辑问题是你有一个边界RECTANGLE,而不是一个正方形。你应该用最短的一边除以一半,所以
You put the question in a way that is all guess work. It turns out that I'm bored so I will try to guess.
You found the bounding rectangle of something you assume or know for certain is a circle. Then you said: the radius of the circle is half one of the sides. Which is logical.
Why did you sum X and Y and then divided by 4 though? It makes no sense at all as it would work only if the rectangle is actyally a sqaure (X = Y) but in that case just pick one and divide by 2, why bother with a sum?
The main logical problem here is that you have a bounding RECTANGLE, not a square. You should take the shortest of its sides and divide by half, so
float radius = ((float)min(cloudSize.X, cloudSize.Y)) / 2;
(我对C#框架知之甚少,所以我用 min
作为f它是C ++,使用你喜欢的最小函数。
(I know little of C# framework so I used min
as f it was C++, use the minimum function you prefer).
这篇关于如何计算圆的直径或半径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文