public static GetAngleBetweenLines ( IntPoint a1, IntPoint a2, IntPoint b1, IntPoint b2 ) : double | ||
a1 | IntPoint | A point on the first line. |
a2 | IntPoint | Another point on the first line. |
b1 | IntPoint | A point on the second line. |
b2 | IntPoint | Another point on the second line. |
리턴 | double |
public PolygonSubType CheckPolygonSubType(List <IntPoint> corners) { PolygonSubType polygonSubType = PolygonSubType.Unknown; PointsCloud.GetBoundingRectangle(corners, out IntPoint minXY, out IntPoint maxXY); IntPoint intPoint = maxXY - minXY; float num = lengthError * (float)(intPoint.X + intPoint.Y) / 2f; if (corners.Count == 3) { float angleBetweenVectors = GeometryTools.GetAngleBetweenVectors(corners[0], corners[1], corners[2]); float angleBetweenVectors2 = GeometryTools.GetAngleBetweenVectors(corners[1], corners[2], corners[0]); float angleBetweenVectors3 = GeometryTools.GetAngleBetweenVectors(corners[2], corners[0], corners[1]); if (System.Math.Abs(angleBetweenVectors - 60f) <= angleError && System.Math.Abs(angleBetweenVectors2 - 60f) <= angleError && System.Math.Abs(angleBetweenVectors3 - 60f) <= angleError) { polygonSubType = PolygonSubType.EquilateralTriangle; } else { if (System.Math.Abs(angleBetweenVectors - angleBetweenVectors2) <= angleError || System.Math.Abs(angleBetweenVectors2 - angleBetweenVectors3) <= angleError || System.Math.Abs(angleBetweenVectors3 - angleBetweenVectors) <= angleError) { polygonSubType = PolygonSubType.IsoscelesTriangle; } if (System.Math.Abs(angleBetweenVectors - 90f) <= angleError || System.Math.Abs(angleBetweenVectors2 - 90f) <= angleError || System.Math.Abs(angleBetweenVectors3 - 90f) <= angleError) { polygonSubType = ((polygonSubType == PolygonSubType.IsoscelesTriangle) ? PolygonSubType.RectangledIsoscelesTriangle : PolygonSubType.RectangledTriangle); } } } else if (corners.Count == 4) { float angleBetweenLines = GeometryTools.GetAngleBetweenLines(corners[0], corners[1], corners[2], corners[3]); float angleBetweenLines2 = GeometryTools.GetAngleBetweenLines(corners[1], corners[2], corners[3], corners[0]); if (angleBetweenLines <= angleError) { polygonSubType = PolygonSubType.Trapezoid; if (angleBetweenLines2 <= angleError) { polygonSubType = PolygonSubType.Parallelogram; if (System.Math.Abs(GeometryTools.GetAngleBetweenVectors(corners[1], corners[0], corners[2]) - 90f) <= angleError) { polygonSubType = PolygonSubType.Rectangle; } float num2 = corners[0].DistanceTo(corners[1]); float num3 = corners[0].DistanceTo(corners[3]); if (System.Math.Abs(num2 - num3) <= num) { polygonSubType = ((polygonSubType == PolygonSubType.Parallelogram) ? PolygonSubType.Rhombus : PolygonSubType.Square); } } } else if (angleBetweenLines2 <= angleError) { polygonSubType = PolygonSubType.Trapezoid; } } return(polygonSubType); }
/// <summary> /// Check sub type of a convex polygon. /// </summary> /// /// <param name="corners">Corners of the convex polygon to check.</param> /// /// <returns>Return detected sub type of the specified shape.</returns> /// /// <remarks><para>The method check corners of a convex polygon detecting /// its subtype. Polygon's corners are usually retrieved using <see cref="IsConvexPolygon"/> /// method, but can be any list of 3-4 points (only sub types of triangles and /// quadrilateral are checked).</para> /// /// <para>See <see cref="AngleError"/> and <see cref="LengthError"/> properties, /// which set acceptable errors for polygon sub type checking.</para> /// </remarks> /// public PolygonSubType CheckPolygonSubType(List <IntPoint> corners) { PolygonSubType subType = PolygonSubType.Unknown; // get bounding rectangle of the points list IntPoint minXY, maxXY; PointsCloud.GetBoundingRectangle(corners, out minXY, out maxXY); // get cloud's size IntPoint cloudSize = maxXY - minXY; float maxLengthDiff = lengthError * (cloudSize.X + cloudSize.Y) / 2; if (corners.Count == 3) { // get angles of the triangle float angle1 = GeometryTools.GetAngleBetweenVectors(IntPoint.ToPoint(corners[0]), IntPoint.ToPoint(corners[1]), IntPoint.ToPoint(corners[2])); float angle2 = GeometryTools.GetAngleBetweenVectors(IntPoint.ToPoint(corners[1]), IntPoint.ToPoint(corners[2]), IntPoint.ToPoint(corners[0])); float angle3 = GeometryTools.GetAngleBetweenVectors(IntPoint.ToPoint(corners[2]), IntPoint.ToPoint(corners[0]), IntPoint.ToPoint(corners[1])); // check for equilateral triangle if ((Math.Abs(angle1 - 60) <= angleError) && (Math.Abs(angle2 - 60) <= angleError) && (Math.Abs(angle3 - 60) <= angleError)) { subType = PolygonSubType.EquilateralTriangle; } else { // check for isosceles triangle if ((Math.Abs(angle1 - angle2) <= angleError) || (Math.Abs(angle2 - angle3) <= angleError) || (Math.Abs(angle3 - angle1) <= angleError)) { subType = PolygonSubType.IsoscelesTriangle; } // check for rectangled triangle if ((Math.Abs(angle1 - 90) <= angleError) || (Math.Abs(angle2 - 90) <= angleError) || (Math.Abs(angle3 - 90) <= angleError)) { subType = (subType == PolygonSubType.IsoscelesTriangle) ? PolygonSubType.RectangledIsoscelesTriangle : PolygonSubType.RectangledTriangle; } } } else if (corners.Count == 4) { // get angles between 2 pairs of opposite sides float angleBetween1stPair = GeometryTools.GetAngleBetweenLines(IntPoint.ToPoint(corners[0]), IntPoint.ToPoint(corners[1]), IntPoint.ToPoint(corners[2]), IntPoint.ToPoint(corners[3])); float angleBetween2ndPair = GeometryTools.GetAngleBetweenLines(IntPoint.ToPoint(corners[1]), IntPoint.ToPoint(corners[2]), IntPoint.ToPoint(corners[3]), IntPoint.ToPoint(corners[0])); // check 1st pair for parallelism if (angleBetween1stPair <= angleError) { subType = PolygonSubType.Trapezoid; // check 2nd pair for parallelism if (angleBetween2ndPair <= angleError) { subType = PolygonSubType.Parallelogram; // check angle between adjacent sides if (Math.Abs(GeometryTools.GetAngleBetweenVectors(IntPoint.ToPoint(corners[1]), IntPoint.ToPoint(corners[0]), IntPoint.ToPoint(corners[2])) - 90) <= angleError) { subType = PolygonSubType.Rectangle; } // get length of 2 adjacent sides float side1Length = (float)corners[0].DistanceTo(corners[1]); float side2Length = (float)corners[0].DistanceTo(corners[3]); if (Math.Abs(side1Length - side2Length) <= maxLengthDiff) { subType = (subType == PolygonSubType.Parallelogram) ? PolygonSubType.Rhombus : PolygonSubType.Square; } } } else { // check 2nd pair for parallelism - last chence to detect trapezoid if (angleBetween2ndPair <= angleError) { subType = PolygonSubType.Trapezoid; } } } return(subType); }