Click here to Skip to main content
15,891,657 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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();
Posted
Updated 13-Mar-18 22:49pm
Comments
Richard MacCutchan 14-Mar-18 4:06am    
What is the question?
Tusshar Samrit 14-Mar-18 4:08am    
i m getting wrong value or radius
Richard MacCutchan 14-Mar-18 4:11am    
What does that mean?
OriginalGriff 14-Mar-18 4:13am    
Remember that we have no idea what data you are feeding that, or what you expect to get - so give us examples, show us what you input, what results you expect, and what values you get. And we have no idea what your _shapeChecker.IsCircle method does - except it appears to calculate the center and radius, so it may be relevant to your "wrong value or radius" problem.
Tusshar Samrit 14-Mar-18 4:54am    
https://drive.google.com/open?id=1LhfQZRa6J4b9cbtkiMjisAx-fd-5Tyh-

1 solution

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

C++
float radius = ((float)min(cloudSize.X, cloudSize.Y)) / 2;


(I know little of C# framework so I used min as f it was C++, use the minimum function you prefer).
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900