简体   繁体   中英

How to determine shape is Semicircle by given point collection?

Here is point collection of polygons

<Polygon Points="24,188,24,183,25,176,26,172,29,166,33,160,38,155,44,151,50,148,54,147,61,146,67,146,74,147,78,148,84,151,90,155,95,160,99,166,102,172,103,176,104,183,104,188" Stroke="Black" StrokeThickness="1" />
<Polygon Points="568,263,520,263,520,256,521,253,523,249,526,245,531,241,536,239,540,238,548,238,552,239,557,241,562,245,565,249,567,253,568,256,568,263" Stroke="Black" StrokeThickness="1" />

that gives me below shapes.

在此处输入图片说明

在此处输入图片说明

I need to check the shape is a semicircle or not? Please anyone can guide me to determine. Is it semicircle?

I will only get collection before drawing only I should determine the shapes. It can be any(Rectangle, Line, Semicircle, curve etc.)I am able to find a rectangle, triangle and lines shape from point collection. like for a rectangle, I am checking its opposite faces should be equal and inside angle should be 90 degrees.

  public bool IsRectangle()
        {                
            var pointColl = polygon.PointCollection;
            bool isRightAngle = false;

            if (polygon == null || pointColl == null)
            {
                return false;
            }
            if (pointColl.Count == 5)
            {
                double length1 = (pointColl[0] - pointColl[1]).LengthSquared;
                double width1 = (pointColl[1] - pointColl[2]).LengthSquared;
                double length2 = (pointColl[2] - pointColl[3]).LengthSquared;
                double width2 = (pointColl[3] - pointColl[0]).LengthSquared;

                if ((length1 == length2 && length1 != 0) && (width1 == width2 && width1 != 0))
                    isRightAngle = CalculateAngle(polygon);
            }
            else
            {
                isRightAngle = false;
            }

Can I write something like this for a semicircle or circular shape detection? Thanks in advance.

What defines a shape as being a semicircle?

In the true sense of the word, neither of your shapes are semi-circles as they are both composed of straight line segments.

How many points does a shape need to be considered as a semi-circle (is triangle sufficiently round enough). What is the margin of error of each point on the circumference (some percentage of the radius) before a shape is no longer considered to be semi-circular.

Some pseudo code for you ...

  1. Given a collection of n points P1, P2 .. Pn
  2. For each pair of points, calculate the distance between them.
  3. The two points with the maximum distance between them (Pa & Pb) are considered to be the diameter (flat side) of the semi circle.
  4. The centre point of the semi-circle is the mid point between Pa and Pb.
  5. The distance from Pa & Pb to the centre point is radius R.
  6. For each remaining point in the collection, calculate the distance to the centre point. If this distance lies within (1 +/- e) * R for all points, then the shape is a semi-circle. The value of e is left for you to define.

Note that this method will work whatever the orientation of the semi-circle. If you need something more specific then also check the slope of the line from Pa to Pb.

Algorithm:

1) Take 3 points from polygon.

2) Estimate circle from them using this method (or any other).

3) Check if other points from given poligon are placed on the estimated circle.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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