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 ...
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.