//check if a given polygon2d has any of its longer edges aligned with any edge of the containerpolygon2d internal static bool CheckLineGetsExternalWall(Line2d lineA, Polygon2d containerPoly) { bool check = false; if (!ValidateObject.CheckPoly(containerPoly)) { return(check); } Polygon2d containerPolyReg = new Polygon2d(containerPoly.Points); for (int i = 0; i < containerPoly.Points.Count; i++) { int a = i, b = i + 1; if (i == containerPolyReg.Points.Count - 1) { b = 0; } Line2d lineB = Line2d.ByStartPointEndPoint(containerPolyReg.Points[a], containerPolyReg.Points[b]); check = GraphicsUtility.LineAdjacencyCheck(lineA, lineB); if (check) { break; } } return(check); }
//check if a given polygon2d has any of its longer edges aligned with any edge of the containerpolygon2d internal static bool CheckPolyGetsExternalWall(Polygon2d poly, Polygon2d containerPoly, double shortEdgeDist = 16, bool tag = true) { bool check = false; if (!ValidateObject.CheckPoly(poly)) { return(check); } Polygon2d polyReg = new Polygon2d(null); //make given polys reduce number of points if (tag) { polyReg = new Polygon2d(poly.Points); } else { polyReg = poly; } Polygon2d containerPolyReg = new Polygon2d(containerPoly.Points); for (int i = 0; i < polyReg.Points.Count; i++) { int a = i, b = i + 1; double eps = 0; if (i == polyReg.Points.Count - 1) { b = 0; } double distance = PointUtility.DistanceBetweenPoints(polyReg.Points[a], polyReg.Points[b]); List <double> spansSorted = PolygonUtility.GetPolySpan(containerPolyReg); if (distance <= spansSorted[0] * 0.75) { continue; } Line2d lineA = Line2d.ByStartPointEndPoint(polyReg.Points[a], polyReg.Points[b]); for (int j = 0; j < containerPolyReg.Points.Count; j++) { int c = j, d = j + 1; if (j == containerPolyReg.Points.Count - 1) { d = 0; } Line2d lineB = Line2d.ByStartPointEndPoint(containerPolyReg.Points[c], containerPolyReg.Points[d]); check = GraphicsUtility.LineAdjacencyCheck(lineA, lineB, eps); if (check) { break; } } if (check) { break; } } return(check); }
//make the given poly all points orthonogonal to each other internal static Polygon2d MakePolyPointsOrtho(Polygon2d poly) { Polygon2d polyReg = new Polygon2d(poly.Points); List <Point2d> ptForOrthoPoly = new List <Point2d>(); for (int i = 0; i < polyReg.Points.Count; i++) { Point2d pt = Point2d.ByCoordinates(polyReg.Points[i].X, polyReg.Points[i].Y); ptForOrthoPoly.Add(pt); } for (int i = 0; i < polyReg.Points.Count; i++) { int a = i, b = i + 1; double eps = 50; if (i == polyReg.Points.Count - 1) { b = 0; } Line2d line = new Line2d(polyReg.Points[a], polyReg.Points[b]); if (ValidateObject.CheckLineOrient(line) == -1) { //double diffX = Math.Abs(line.StartPoint.X - line.EndPoint.X); //double diffY = Math.Abs(line.StartPoint.Y - line.EndPoint.Y); Point2d cenPoly = PolygonUtility.CentroidOfPoly(polyReg); Point2d ptEndA = Point2d.ByCoordinates(polyReg.Points[a].X + eps, polyReg.Points[a].Y); Line2d refLineA = Line2d.ByStartPointEndPoint(polyReg.Points[a], ptEndA); Point2d ptEndB = Point2d.ByCoordinates(polyReg.Points[b].X + eps, polyReg.Points[b].Y); Line2d refLineB = Line2d.ByStartPointEndPoint(polyReg.Points[b], ptEndB); Point2d projectedPtA = GraphicsUtility.ProjectedPointOnLine(refLineB, polyReg.Points[a]); Point2d projectedPtB = GraphicsUtility.ProjectedPointOnLine(refLineA, polyReg.Points[b]); Vector2d vecA = new Vector2d(projectedPtA, cenPoly); Vector2d vecB = new Vector2d(projectedPtB, cenPoly); double vecALength = vecA.Length; double vecBLength = vecB.Length; if (vecALength > vecBLength) { //ptForOrthoPoly[i] = projectedPtA; ptForOrthoPoly.Insert(b, projectedPtB); } else { //ptForOrthoPoly[i] = projectedPtB; ptForOrthoPoly.Insert(b, projectedPtA); } /* * if (diffX > diffY) * { * Point2d ptEndA = Point2d.ByCoordinates(polyReg.Points[a].X, polyReg.Points[a].Y + eps); * Line2d refLineA = Line2d.ByStartPointEndPoint(polyReg.Points[a], ptEndA); * refLineA = LineUtility.extend(refLineA); * * Point2d ptEndB = Point2d.ByCoordinates(polyReg.Points[b].X, polyReg.Points[b].Y + eps); * Line2d refLineB = Line2d.ByStartPointEndPoint(polyReg.Points[b], ptEndB); * refLineB = LineUtility.extend(refLineB); * * Point2d projectedPtA = GraphicsUtility.ProjectedPointOnLine(refLineB, polyReg.Points[a]); * Point2d projectedPtB = GraphicsUtility.ProjectedPointOnLine(refLineA, polyReg.Points[b]); * * Vector2d vecA = new Vector2d(projectedPtA, cenPoly); * Vector2d vecB = new Vector2d(projectedPtB, cenPoly); * double vecALength = vecA.Length; * double vecBLength = vecB.Length; * if(vecALength < vecBLength) * { * //ptForOrthoPoly[i] = projectedPtA; * ptForOrthoPoly.Insert(b, projectedPtB); * } * else * { * //ptForOrthoPoly[i] = projectedPtB; * ptForOrthoPoly.Insert(b, projectedPtA); * } * } * else * { * * Point2d ptEndA = Point2d.ByCoordinates(polyReg.Points[a].X + eps, polyReg.Points[a].Y); * Line2d refLineA = Line2d.ByStartPointEndPoint(polyReg.Points[a], ptEndA); * refLineA = LineUtility.extend(refLineA); * * Point2d ptEndB = Point2d.ByCoordinates(polyReg.Points[b].X + eps, polyReg.Points[b].Y); * Line2d refLineB = Line2d.ByStartPointEndPoint(polyReg.Points[b], ptEndB); * refLineB = LineUtility.extend(refLineB); * * Point2d projectedPtA = GraphicsUtility.ProjectedPointOnLine(refLineB, polyReg.Points[a]); * Point2d projectedPtB = GraphicsUtility.ProjectedPointOnLine(refLineA, polyReg.Points[b]); * * Vector2d vecA = new Vector2d(projectedPtA, cenPoly); * Vector2d vecB = new Vector2d(projectedPtB, cenPoly); * double vecALength = vecA.Length; * double vecBLength = vecB.Length; * if (vecALength < vecBLength) * { * //ptForOrthoPoly[i] = projectedPtA; * ptForOrthoPoly.Insert(b, projectedPtB); * } * else * { * //ptForOrthoPoly[i] = projectedPtB; * ptForOrthoPoly.Insert(b, projectedPtB); * } * } */ } } return(new Polygon2d(ptForOrthoPoly)); }