public List <MWPoint2D> ExpandWall(MWPoint2D p1, MWPoint2D p2) { MWVector2D v = new MWVector2D(p2.X - p1.X, p2.Y - p1.Y); v = v.Normalize(); MWVector2D n = new MWVector2D(-v.Y, v.X); return(new List <MWPoint2D>() { new MWPoint2D(p1.X + this.WallThickness / 1e3 / 2 * (+n.X - v.X), p1.Y + this.WallThickness / 1e3 / 2 * (+n.Y - v.Y)), new MWPoint2D(p1.X + this.WallThickness / 1e3 / 2 * (-n.X - v.X), p1.Y + this.WallThickness / 1e3 / 2 * (-n.Y - v.Y)), new MWPoint2D(p2.X + this.WallThickness / 1e3 / 2 * (-n.X + v.X), p2.Y + this.WallThickness / 1e3 / 2 * (-n.Y + v.Y)), new MWPoint2D(p2.X + this.WallThickness / 1e3 / 2 * (+n.X + v.X), p2.Y + this.WallThickness / 1e3 / 2 * (+n.Y + v.Y)), }); }
public void ProcessColumns() { for (int i = 0; i < PicColumns?.Count; i++) { RotatedRect rect = CvInvoke.MinAreaRect(PicColumns[i].Select(p => new PointF((float)p.X, (float)p.Y)).ToArray()); var corners = rect.GetVertices().Select(p => new MWPoint2D(p.X, p.Y)).ToList(); double l1 = Points.Distance(corners[0], corners[1]); double l2 = Points.Distance(corners[1], corners[2]); List <MWPoint2D> newPoints = new List <MWPoint2D>(); MWPoint2D center = new MWPoint2D(0.5 * (corners[0].X + corners[2].X), 0.5 * (corners[0].Y + corners[2].Y)); ColumnDims cd; MWVector2D v; if (l1 > l2) { double ratio = l1 / l2; cd = ColDims.Aggregate(ColDims[0], (closest, next) => Math.Abs(ratio - next.Ratio) < Math.Abs(ratio - closest.Ratio) ? next : closest); v = new MWVector2D(corners[1].X - corners[0].X, corners[1].Y - corners[0].Y); } else { double ratio = l2 / l1; cd = ColDims.Aggregate(ColDims[0], (closest, next) => Math.Abs(ratio - next.Ratio) < Math.Abs(ratio - closest.Ratio) ? next : closest); v = new MWVector2D(corners[2].X - corners[1].X, corners[2].Y - corners[1].Y); } double L = Math.Max(cd.D1, cd.D2) / 1e3; double W = Math.Min(cd.D1, cd.D2) / 1e3; v = v.Normalize(); MWVector2D n = new MWVector2D(-v.Y, v.X); newPoints.Add(new MWPoint2D(+0.5 * L * v.X + 0.5 * W * n.X, +0.5 * L * v.Y + 0.5 * W * n.Y)); newPoints.Add(new MWPoint2D(+0.5 * L * v.X - 0.5 * W * n.X, +0.5 * L * v.Y - 0.5 * W * n.Y)); newPoints.Add(new MWPoint2D(-0.5 * L * v.X - 0.5 * W * n.X, -0.5 * L * v.Y - 0.5 * W * n.Y)); newPoints.Add(new MWPoint2D(-0.5 * L * v.X + 0.5 * W * n.X, -0.5 * L * v.Y + 0.5 * W * n.Y)); Columns.Add(new Column() { RawCenter = center, SectionPoints = newPoints }); } RescaleColumns(); }