public static System.Windows.Media.Brush PatternToBrush(HatchPattern myPattern, AciColor myColor) { VisualBrush vBrush = new VisualBrush(); System.Windows.Media.Brush resBrush = vBrush; if (myPattern.Fill == netDxf.Entities.HatchFillType.PatternFill) { System.Windows.Shapes.Path path1 = new System.Windows.Shapes.Path(); path1.StrokeThickness = 1; path1.Stroke = AciColorToBrush(myColor); var it1 = new Vector2(myPattern.LineDefinitions[0].Origin.X, myPattern.LineDefinitions[0].Origin.Y); System.Windows.Point p0 = TypeConverter.Vertex2ToPoint(it1); double deltaY = myPattern.LineDefinitions[0].Delta.Y; if (myPattern.Name == "LINE") { System.Windows.Point p1 = p0; System.Windows.Point p2 = new System.Windows.Point(p1.X, p1.Y + 10); /*path1.Data=Geometry.Parse("M 5 0 L 5 10 Z");*/ path1.Data = DrawUtils.GetStreamGeoLine(p1, p2); } vBrush.TileMode = TileMode.Tile; vBrush.Viewport = new Rect(p0.X, p0.Y, deltaY, deltaY); vBrush.ViewportUnits = BrushMappingMode.Absolute; vBrush.Viewbox = new Rect(p0.X, p0.Y, 10, 10); vBrush.ViewboxUnits = BrushMappingMode.Absolute; vBrush.Visual = path1; vBrush.RelativeTransform = new RotateTransform(myPattern.Angle, 5, 5); resBrush = vBrush; } else if (myPattern.Fill == netDxf.Entities.HatchFillType.SolidFill) { if (myPattern.GetType() == typeof(HatchGradientPattern)) { resBrush = PatternSolidFillToBrush((HatchGradientPattern)myPattern, myColor); } } return(resBrush); }
private void CmbPatternTypeSelectedIndexChanged(object sender, EventArgs e) { if ((string)cmbPatternType.SelectedItem == "Simple") { if (tabPatternProperties.TabPages.Contains(tabPicture)) { tabPatternProperties.TabPages.Remove(tabPicture); } if (tabPatternProperties.TabPages.Contains(tabGradient)) { tabPatternProperties.TabPages.Remove(tabGradient); } if (tabPatternProperties.TabPages.Contains(tabHatch)) { tabPatternProperties.TabPages.Remove(tabHatch); } if (tabPatternProperties.TabPages.Contains(tabSimple) == false) { tabPatternProperties.TabPages.Add(tabSimple); tabPatternProperties.SelectedTab = tabSimple; } } if ((string)cmbPatternType.SelectedItem == "Picture") { if (tabPatternProperties.TabPages.Contains(tabSimple)) { tabPatternProperties.TabPages.Remove(tabSimple); } if (tabPatternProperties.TabPages.Contains(tabGradient)) { tabPatternProperties.TabPages.Remove(tabGradient); } if (tabPatternProperties.TabPages.Contains(tabHatch)) { tabPatternProperties.TabPages.Remove(tabHatch); } if (tabPatternProperties.TabPages.Contains(tabPicture) == false) { tabPatternProperties.TabPages.Add(tabPicture); tabPatternProperties.SelectedTab = tabPicture; } } if ((string)cmbPatternType.SelectedItem == "Gradient") { if (tabPatternProperties.TabPages.Contains(tabSimple)) { tabPatternProperties.TabPages.Remove(tabSimple); } if (tabPatternProperties.TabPages.Contains(tabPicture)) { tabPatternProperties.TabPages.Remove(tabPicture); } if (tabPatternProperties.TabPages.Contains(tabHatch)) { tabPatternProperties.TabPages.Remove(tabHatch); } if (tabPatternProperties.TabPages.Contains(tabGradient) == false) { tabPatternProperties.TabPages.Add(tabGradient); tabPatternProperties.SelectedTab = tabGradient; } } if ((string)cmbPatternType.SelectedItem == "Hatch") { if (tabPatternProperties.TabPages.Contains(tabSimple)) { tabPatternProperties.TabPages.Remove(tabSimple); } if (tabPatternProperties.TabPages.Contains(tabPicture)) { tabPatternProperties.TabPages.Remove(tabPicture); } if (tabPatternProperties.TabPages.Contains(tabGradient)) { tabPatternProperties.TabPages.Remove(tabGradient); } if (tabPatternProperties.TabPages.Contains(tabHatch) == false) { tabPatternProperties.TabPages.Add(tabHatch); tabPatternProperties.SelectedTab = tabHatch; } } if (_ignoreChanges) { return; } int index = ccPatterns.Patterns.IndexOf(ccPatterns.SelectedPattern); if (index == -1) { return; } IPattern oldPattern = ccPatterns.SelectedPattern; if ((string)cmbPatternType.SelectedItem == "Simple") { SimplePattern sp = new SimplePattern(); if (oldPattern != null) { sp.CopyOutline(oldPattern); } ccPatterns.Patterns[index] = sp; ccPatterns.RefreshList(); ccPatterns.SelectedPattern = sp; UpdateSimplePatternControls(sp); } if ((string)cmbPatternType.SelectedItem == "Picture") { PicturePattern pp = new PicturePattern(); if (oldPattern != null) { pp.CopyOutline(oldPattern); } ccPatterns.Patterns[index] = pp; ccPatterns.RefreshList(); ccPatterns.SelectedPattern = pp; UpdatePicturePatternControls(pp); } if ((string)cmbPatternType.SelectedItem == "Gradient") { GradientPattern gp = new GradientPattern(); if (oldPattern != null) { gp.CopyOutline(oldPattern); } ccPatterns.Patterns[index] = gp; ccPatterns.RefreshList(); ccPatterns.SelectedPattern = gp; UpdateGradientPatternControls(gp); } if ((string)cmbPatternType.SelectedItem == "Hatch") { HatchPattern hp = new HatchPattern(); if (oldPattern != null) { hp.CopyOutline(oldPattern); } ccPatterns.Patterns[index] = hp; ccPatterns.RefreshList(); ccPatterns.SelectedPattern = hp; } }
// Store polygon from dxf file public List <Polygon> getArea(string filename) { // read the dxf file DxfDocument dxfTest; dxfTest = OpenProfile(filename); int numberSegments = 16; int blockNumber = -1; var polygons = new List <Polygon>(); var Poly = new Polygon(); // loop over all relevant blacks and store the hatch boundaries foreach (var bl in dxfTest.Blocks) { // loop over the enteties in the block and decompose them if they belong to an aluminum layer foreach (var ent in bl.Entities) { if (ent.Layer.Name.ToString() == "0S-Alu hatch") { Poly = new Polygon(); blockNumber++; HatchPattern hp = HatchPattern.Solid; Hatch myHatch = new Hatch(hp, false); myHatch = (Hatch)ent; int pathNumber = -1; foreach (var bPath in myHatch.BoundaryPaths) { pathNumber++; var contour = new List <Vertex>(); // Store the contour for (int i = 0; i < bPath.Edges.Count; i++) { switch (bPath.Edges[i].Type.ToString().ToLower()) { case "line": var myLine = (netDxf.Entities.HatchBoundaryPath.Line)bPath.Edges[i]; var vLine = new Vertex(); vLine.X = myLine.Start.X; vLine.Y = myLine.Start.Y; contour.Add(vLine); break; case "arc": var myArc = (netDxf.Entities.HatchBoundaryPath.Arc)bPath.Edges[i]; double delta = (myArc.EndAngle - myArc.StartAngle) / numberSegments; for (int j = 0; j < numberSegments; j++) { var vArc = new Vertex(); double angleArc = (myArc.StartAngle + j * delta) * Math.PI / 180.0; if (myArc.IsCounterclockwise == true) { vArc.X = myArc.Center.X + myArc.Radius * Math.Cos(angleArc); vArc.Y = myArc.Center.Y + myArc.Radius * Math.Sin(angleArc); } else { vArc.X = myArc.Center.X + myArc.Radius * Math.Cos(Math.PI + angleArc); vArc.Y = myArc.Center.Y + myArc.Radius * Math.Sin(Math.PI - angleArc); } contour.Add(vArc); } break; case "ellipse": var myEllipse = (netDxf.Entities.HatchBoundaryPath.Ellipse)bPath.Edges[i]; double deltaEllipse = (myEllipse.EndAngle - myEllipse.StartAngle) / numberSegments; for (int j = 0; j < numberSegments; j++) { var vEllipse = new Vertex(); var ellipseRadius = Math.Sqrt(Math.Pow(myEllipse.EndMajorAxis.X, 2) + Math.Pow(myEllipse.EndMajorAxis.Y, 2)); double angleEllipse = (myEllipse.StartAngle + j * deltaEllipse) * Math.PI / 180.0; if (myEllipse.IsCounterclockwise == true) { vEllipse.X = myEllipse.Center.X + ellipseRadius * Math.Cos(angleEllipse); vEllipse.Y = myEllipse.Center.Y + ellipseRadius * Math.Sin(angleEllipse); } else { vEllipse.X = myEllipse.Center.X + ellipseRadius * Math.Cos(Math.PI + angleEllipse); vEllipse.Y = myEllipse.Center.Y + ellipseRadius * Math.Sin(Math.PI - angleEllipse); } contour.Add(vEllipse); } break; } } bool hole = true; // Add to the poly if (blockNumber == 0 || blockNumber == 1) { if (pathNumber == 0) { hole = false; } Poly.AddContour(points: contour, marker: 0, hole: hole); } } polygons.Add(Poly); } } } numberSegments = 16; // changed now blockNumber = -1; foreach (var bl in dxfTest.Blocks) { // loop over the enteties in the block and decompose them if they belong to an aluminum layer foreach (var ent in bl.Entities) { if (ent.Layer.Name.ToString() == "0S-Plastic hatch") { Poly = new Polygon(); blockNumber++; HatchPattern hp = HatchPattern.Solid; Hatch myHatch = new Hatch(hp, false); myHatch = (Hatch)ent; int pathNumber = -1; foreach (var bPath in myHatch.BoundaryPaths) { pathNumber++; var contour = new List <Vertex>(); // Store the contour for (int i = 0; i < bPath.Edges.Count; i++) { switch (bPath.Edges[i].Type.ToString().ToLower()) { case "line": var myLine = (netDxf.Entities.HatchBoundaryPath.Line)bPath.Edges[i]; var vLine = new Vertex(); vLine.X = myLine.Start.X; vLine.Y = myLine.Start.Y; contour.Add(vLine); break; case "arc": var myArc = (netDxf.Entities.HatchBoundaryPath.Arc)bPath.Edges[i]; double delta = (myArc.EndAngle - myArc.StartAngle) / numberSegments; for (int j = 0; j < numberSegments; j++) { var vArc = new Vertex(); double angleArc = (myArc.StartAngle + j * delta) * Math.PI / 180.0; if (myArc.IsCounterclockwise == true) { vArc.X = myArc.Center.X + myArc.Radius * Math.Cos(angleArc); vArc.Y = myArc.Center.Y + myArc.Radius * Math.Sin(angleArc); } else { vArc.X = myArc.Center.X + myArc.Radius * Math.Cos(Math.PI + angleArc); vArc.Y = myArc.Center.Y + myArc.Radius * Math.Sin(Math.PI - angleArc); } contour.Add(vArc); } break; case "ellipse": var myEllipse = (netDxf.Entities.HatchBoundaryPath.Ellipse)bPath.Edges[i]; double deltaEllipse = (myEllipse.EndAngle - myEllipse.StartAngle) / numberSegments; for (int j = 0; j < numberSegments; j++) { var vEllipse = new Vertex(); var ellipseRadius = Math.Sqrt(Math.Pow(myEllipse.EndMajorAxis.X, 2) + Math.Pow(myEllipse.EndMajorAxis.Y, 2)); double angleEllipse = (myEllipse.StartAngle + j * deltaEllipse) * Math.PI / 180.0; if (myEllipse.IsCounterclockwise == true) { vEllipse.X = myEllipse.Center.X + ellipseRadius * Math.Cos(angleEllipse); vEllipse.Y = myEllipse.Center.Y + ellipseRadius * Math.Sin(angleEllipse); } else { vEllipse.X = myEllipse.Center.X + ellipseRadius * Math.Cos(Math.PI + angleEllipse); vEllipse.Y = myEllipse.Center.Y + ellipseRadius * Math.Sin(Math.PI - angleEllipse); } contour.Add(vEllipse); } break; } } bool hole = true; // Add to the poly if (blockNumber == 0 || blockNumber == 1) { if (pathNumber == 0) { hole = false; } Poly.AddContour(points: contour, marker: 0, hole: hole); } } polygons.Add(Poly); } } } numberSegments = 16; // changed now blockNumber = -1; foreach (var bl in dxfTest.Blocks) { // loop over the enteties in the block and decompose them if they belong to an aluminum layer foreach (var ent in bl.Entities) { if (ent.Layer.Name.ToString() == "0S-PT hatch") { Poly = new Polygon(); blockNumber++; HatchPattern hp = HatchPattern.Solid; Hatch myHatch = new Hatch(hp, false); myHatch = (Hatch)ent; int pathNumber = -1; foreach (var bPath in myHatch.BoundaryPaths) { pathNumber++; var contour = new List <Vertex>(); // Store the contour for (int i = 0; i < bPath.Edges.Count; i++) { switch (bPath.Edges[i].Type.ToString().ToLower()) { case "line": var myLine = (netDxf.Entities.HatchBoundaryPath.Line)bPath.Edges[i]; var vLine = new Vertex(); vLine.X = myLine.Start.X; vLine.Y = myLine.Start.Y; contour.Add(vLine); break; case "arc": var myArc = (netDxf.Entities.HatchBoundaryPath.Arc)bPath.Edges[i]; double delta = (myArc.EndAngle - myArc.StartAngle) / numberSegments; for (int j = 0; j < numberSegments; j++) { var vArc = new Vertex(); double angleArc = (myArc.StartAngle + j * delta) * Math.PI / 180.0; if (myArc.IsCounterclockwise == true) { vArc.X = myArc.Center.X + myArc.Radius * Math.Cos(angleArc); vArc.Y = myArc.Center.Y + myArc.Radius * Math.Sin(angleArc); } else { vArc.X = myArc.Center.X + myArc.Radius * Math.Cos(Math.PI + angleArc); vArc.Y = myArc.Center.Y + myArc.Radius * Math.Sin(Math.PI - angleArc); } contour.Add(vArc); } break; case "ellipse": var myEllipse = (netDxf.Entities.HatchBoundaryPath.Ellipse)bPath.Edges[i]; double deltaEllipse = (myEllipse.EndAngle - myEllipse.StartAngle) / numberSegments; for (int j = 0; j < numberSegments; j++) { var vEllipse = new Vertex(); var ellipseRadius = Math.Sqrt(Math.Pow(myEllipse.EndMajorAxis.X, 2) + Math.Pow(myEllipse.EndMajorAxis.Y, 2)); double angleEllipse = (myEllipse.StartAngle + j * deltaEllipse) * Math.PI / 180.0; if (myEllipse.IsCounterclockwise == true) { vEllipse.X = myEllipse.Center.X + ellipseRadius * Math.Cos(angleEllipse); vEllipse.Y = myEllipse.Center.Y + ellipseRadius * Math.Sin(angleEllipse); } else { vEllipse.X = myEllipse.Center.X + ellipseRadius * Math.Cos(Math.PI + angleEllipse); vEllipse.Y = myEllipse.Center.Y + ellipseRadius * Math.Sin(Math.PI - angleEllipse); } contour.Add(vEllipse); } break; } } bool hole = true; // Add to the poly if (blockNumber == 0 || blockNumber == 1) { if (pathNumber == 0) { hole = false; } Poly.AddContour(points: contour, marker: 0, hole: hole); } } polygons.Add(Poly); } } } return(polygons); }
private static void FilesTest() { LineType lineType = LineType.FromFile("acad.lin", "ACAD_ISO15W100"); HatchPattern hatch = HatchPattern.FromFile("acad.pat", "zigzag"); }
private static void CustomHatchPattern() { DxfDocument dxf = new DxfDocument(); Polyline poly = new Polyline(); poly.Vertexes.Add(new PolylineVertex(-10, -10)); poly.Vertexes.Add(new PolylineVertex(10, -10)); poly.Vertexes.Add(new PolylineVertex(10, 10)); poly.Vertexes.Add(new PolylineVertex(-10, 10)); poly.Vertexes[2].Bulge = 1; poly.IsClosed = true; Polyline poly2 = new Polyline(); poly2.Vertexes.Add(new PolylineVertex(-5, -5)); poly2.Vertexes.Add(new PolylineVertex(5, -5)); poly2.Vertexes.Add(new PolylineVertex(5, 5)); poly2.Vertexes.Add(new PolylineVertex(-5, 5)); poly2.Vertexes[1].Bulge = -0.25; poly2.IsClosed = true; Polyline poly3 = new Polyline(); poly3.Vertexes.Add(new PolylineVertex(-8, -8)); poly3.Vertexes.Add(new PolylineVertex(-6, -8)); poly3.Vertexes.Add(new PolylineVertex(-6, -6)); poly3.Vertexes.Add(new PolylineVertex(-8, -6)); poly3.IsClosed = true; List <HatchBoundaryPath> boundary = new List <HatchBoundaryPath> { new HatchBoundaryPath(new List <IEntityObject> { poly }), new HatchBoundaryPath(new List <IEntityObject> { poly2 }), new HatchBoundaryPath(new List <IEntityObject> { poly3 }), }; HatchPattern pattern = new HatchPattern("MyPattern", "A custom hatch pattern"); HatchPatternLineDefinition line1 = new HatchPatternLineDefinition(); line1.Angle = 45; line1.Origin = Vector2.Zero; line1.Delta = new Vector2(4, 4); line1.DashPattern.Add(12); line1.DashPattern.Add(-4); pattern.LineDefinitions.Add(line1); HatchPatternLineDefinition line2 = new HatchPatternLineDefinition(); line2.Angle = 135; line2.Origin = new Vector2(2.828427125, 2.828427125); line2.Delta = new Vector2(4, -4); line2.DashPattern.Add(12); line2.DashPattern.Add(-4); pattern.LineDefinitions.Add(line2); Hatch hatch = new Hatch(pattern, boundary); hatch.Layer = new Layer("hatch") { Color = AciColor.Red, LineType = LineType.Continuous }; hatch.Pattern.Angle = 0; hatch.Pattern.Scale = 1; dxf.AddEntity(poly); dxf.AddEntity(poly2); dxf.AddEntity(poly3); dxf.AddEntity(hatch); dxf.Save("hatchTest.dxf", DxfVersion.AutoCad2000); }
private void cmbPatternType_SelectedIndexChanged(object sender, EventArgs e) { if ((string)cmbPatternType.SelectedItem == "Simple") { if (tabPatternProperties.TabPages.Contains(tabPicture)) { tabPatternProperties.TabPages.Remove(tabPicture); } if (tabPatternProperties.TabPages.Contains(tabGradient)) { tabPatternProperties.TabPages.Remove(tabGradient); } if (tabPatternProperties.TabPages.Contains(tabHatch)) { tabPatternProperties.TabPages.Remove(tabHatch); } if (tabPatternProperties.TabPages.Contains(tabSimple) == false) { tabPatternProperties.TabPages.Add(tabSimple); tabPatternProperties.SelectedTab = tabSimple; } } if ((string)cmbPatternType.SelectedItem == "Picture") { if (tabPatternProperties.TabPages.Contains(tabSimple)) { tabPatternProperties.TabPages.Remove(tabSimple); } if (tabPatternProperties.TabPages.Contains(tabGradient)) { tabPatternProperties.TabPages.Remove(tabGradient); } if (tabPatternProperties.TabPages.Contains(tabHatch)) { tabPatternProperties.TabPages.Remove(tabHatch); } if (tabPatternProperties.TabPages.Contains(tabPicture) == false) { tabPatternProperties.TabPages.Add(tabPicture); tabPatternProperties.SelectedTab = tabPicture; } } if ((string)cmbPatternType.SelectedItem == "Gradient") { if (tabPatternProperties.TabPages.Contains(tabSimple)) { tabPatternProperties.TabPages.Remove(tabSimple); } if (tabPatternProperties.TabPages.Contains(tabPicture)) { tabPatternProperties.TabPages.Remove(tabPicture); } if (tabPatternProperties.TabPages.Contains(tabHatch)) { tabPatternProperties.TabPages.Remove(tabHatch); } if (tabPatternProperties.TabPages.Contains(tabGradient) == false) { tabPatternProperties.TabPages.Add(tabGradient); tabPatternProperties.SelectedTab = tabGradient; } } if ((string)cmbPatternType.SelectedItem == "Hatch") { if (tabPatternProperties.TabPages.Contains(tabSimple)) { tabPatternProperties.TabPages.Remove(tabSimple); } if (tabPatternProperties.TabPages.Contains(tabPicture)) { tabPatternProperties.TabPages.Remove(tabPicture); } if (tabPatternProperties.TabPages.Contains(tabGradient)) { tabPatternProperties.TabPages.Remove(tabGradient); } if (tabPatternProperties.TabPages.Contains(tabHatch) == false) { tabPatternProperties.TabPages.Add(tabHatch); tabPatternProperties.SelectedTab = tabHatch; } } if (_ignoreChanges) return; int index = ccPatterns.Patterns.IndexOf(ccPatterns.SelectedPattern); if (index == -1) return; IPattern oldPattern = ccPatterns.SelectedPattern; if ((string)cmbPatternType.SelectedItem == "Simple") { SimplePattern sp = new SimplePattern(); if (oldPattern != null) sp.CopyOutline(oldPattern); ccPatterns.Patterns[index] = sp; ccPatterns.RefreshList(); ccPatterns.SelectedPattern = sp; UpdateSimplePatternControls(sp); } if ((string)cmbPatternType.SelectedItem == "Picture") { PicturePattern pp = new PicturePattern(); if (oldPattern != null) pp.CopyOutline(oldPattern); ccPatterns.Patterns[index] = pp; ccPatterns.RefreshList(); ccPatterns.SelectedPattern = pp; UpdatePicturePatternControls(pp); } if ((string)cmbPatternType.SelectedItem == "Gradient") { GradientPattern gp = new GradientPattern(); if (oldPattern != null) gp.CopyOutline(oldPattern); ccPatterns.Patterns[index] = gp; ccPatterns.RefreshList(); ccPatterns.SelectedPattern = gp; UpdateGradientPatternControls(gp); } if ((string)cmbPatternType.SelectedItem == "Hatch") { HatchPattern hp = new HatchPattern(); if (oldPattern != null) hp.CopyOutline(oldPattern); ccPatterns.Patterns[index] = hp; ccPatterns.RefreshList(); ccPatterns.SelectedPattern = hp; } }
// find polygon depth public double dxfPolydepth(string filename) { // read the dxf file DxfDocument dxfTest; var poly = new Polygon(); // dxfTest = OpenProfile("382290.dxf"); dxfTest = OpenProfile(filename); int numberSegments = 16; int blockNumber = -1; // loop over all relevant blacks and store the hatch boundaries foreach (var bl in dxfTest.Blocks) { // loop over the enteties in the block and decompose them if they belong to an aluminum layer foreach (var ent in bl.Entities) { if (ent.Layer.Name.ToString().Contains("0S-Alu hatch")) //(ent.Layer.Name.ToString() == "0S-Alu hatch") { blockNumber++; HatchPattern hp = HatchPattern.Solid; Hatch myHatch = new Hatch(hp, false); myHatch = (Hatch)ent; int pathNumber = -1; foreach (var bPath in myHatch.BoundaryPaths) { pathNumber++; // define the contour list var contour = new List <Vertex>(); for (int i = 0; i < bPath.Edges.Count; i++) { switch (bPath.Edges[i].Type.ToString().ToLower()) { case "line": var myLine = (netDxf.Entities.HatchBoundaryPath.Line)bPath.Edges[i]; var vLine = new Vertex(); vLine.X = myLine.Start.X; vLine.Y = myLine.Start.Y; contour.Add(vLine); break; case "arc": var myArc = (netDxf.Entities.HatchBoundaryPath.Arc)bPath.Edges[i]; double delta = (myArc.EndAngle - myArc.StartAngle) / numberSegments; for (int j = 0; j < numberSegments; j++) { var vArc = new Vertex(); double angleArc = (myArc.StartAngle + j * delta) * Math.PI / 180.0; if (myArc.IsCounterclockwise == true) { vArc.X = myArc.Center.X + myArc.Radius * Math.Cos(angleArc); vArc.Y = myArc.Center.Y + myArc.Radius * Math.Sin(angleArc); } else { vArc.X = myArc.Center.X + myArc.Radius * Math.Cos(Math.PI + angleArc); vArc.Y = myArc.Center.Y + myArc.Radius * Math.Sin(Math.PI - angleArc); } contour.Add(vArc); } break; case "ellipse": var myEllipse = (netDxf.Entities.HatchBoundaryPath.Ellipse)bPath.Edges[i]; double deltaEllipse = (myEllipse.EndAngle - myEllipse.StartAngle) / numberSegments; for (int j = 0; j < numberSegments; j++) { var vEllipse = new Vertex(); var ellipseRadius = Math.Sqrt(Math.Pow(myEllipse.EndMajorAxis.X, 2) + Math.Pow(myEllipse.EndMajorAxis.Y, 2)); double angleEllipse = (myEllipse.StartAngle + j * deltaEllipse) * Math.PI / 180.0; if (myEllipse.IsCounterclockwise == true) { vEllipse.X = myEllipse.Center.X + ellipseRadius * Math.Cos(angleEllipse); vEllipse.Y = myEllipse.Center.Y + ellipseRadius * Math.Sin(angleEllipse); } else { vEllipse.X = myEllipse.Center.X + ellipseRadius * Math.Cos(Math.PI + angleEllipse); vEllipse.Y = myEllipse.Center.Y + ellipseRadius * Math.Sin(Math.PI - angleEllipse); } contour.Add(vEllipse); } break; } } bool hole = true; if (pathNumber == 0) { hole = false; } poly.AddContour(points: contour, marker: 0, hole: hole); } } } } // Get the depth double ytop = double.NegativeInfinity; double ybottom = double.PositiveInfinity; foreach (var vertex in poly.Points) { if (ytop <= vertex.Y) { ytop = vertex.Y; } if (ybottom >= vertex.Y) { ybottom = vertex.Y; } } return(ytop - ybottom); }