Click here to Skip to main content
15,888,351 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
C#
 if (shapeChecker.IsCircle(edgePoints, out center, out radius))
{
    g.DrawEllipse(yellowPen, (float)(center.X - radius), (float)  (center.Y - radius),
       (float)(radius * 2), (float)(radius * 2));
    circleCount++;
    label2.Text = String.Format("Centre Location X:{0}, Y:{1} ",
    center.X, center.Y);
    label3.Text = String.Format("Radius : {0} ", radius);
    x = (int)center.X;
    y = (int)center.Y;
    timer2.Enabled = true;
}

//is Rhombus
else if (shapeChecker.IsConvexPolygon(edgePoints, out corners))
{
    if (shapeChecker.CheckPolygonSubType(corners) == PolygonSubType.Rhombus)
    {
        rhombusCount++;                            
        g.DrawPolygon(bluePen, ToPointsArray(corners));
       //How to know center rhombus??
    }
}

//is rectangle
if (shapeChecker.IsQuadrilateral(edgePoints, out corners))
{
    if (shapeChecker.CheckPolygonSubType(corners) == PolygonSubType.Rectangle)
    {   
        rectangularCount++;                                    
        g.DrawPolygon(redPen, ToPointsArray(corners));
        //How to know center rectangle
    }   
}
Posted
Updated 18-Oct-14 4:35am
v2
Comments
NaibedyaKar 18-Oct-14 3:28am    
Can you take a look at the below link
http://www.codeproject.com/Tips/403031/Extension-methods-for-finding-centers-of-a-rectang

1 solution

The centre of a rhombus is the centre of the bounding rectangle:
 _  _______
|  /      /
| /      /
 /      /  |
/______/ __|
And that's trivial:
C#
/// <summary>
/// Returns the center point of the rectangle
/// </summary>
/// <param name="r"></param>
/// <returns>Center point of the rectangle</returns>
public static Point Center(this Rectangle r)
    {
    return new Point((r.Left + r.Right) / 2, (r.Top + r.Bottom) / 2);
    }
(From the link supplied by NaibedyaKar in the comments above - since I wrote the tip, I can copy it all I want! :laugh: )

Working out the bounding rectangle isn't difficult either: (smallestX, smallestY), (largestX, largestY) are the TLHC and BRHC respectively.
 
Share this answer
 
Comments
Maciej Los 18-Oct-14 11:51am    
5ed twice!
BillWoodruff 20-Oct-14 11:55am    
+5'd (thrice ?)

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