public MarkGeometryArc(Arc arc) : base() { Radius = arc.Radius; StartAngle = GeometricArithmeticModule.ToRadians(arc.StartAngle); EndAngle = GeometricArithmeticModule.ToRadians(arc.EndAngle); CentrePoint = new MarkGeometryPoint(arc.Center); Update(); }
private (string LayerName, MarkGeometryArc Arc) ParseArc(AdvancedLineStreamReader readerIn) { var(success, layerName) = ReadLayerName(readerIn, "AcDbCircle"); if (success) { var result1 = readerIn.FindConsecutiveLines( "100", "AcDbCircle" ); if (!result1.Success) { return(null, null); } } MarkGeometryPoint centrePoint = ReadPointFast(readerIn); // read radius 40 readerIn.ReadLine(); double radius = double.Parse(readerIn.ReadLine()); var result2 = readerIn.FindConsecutiveLines( "100", "AcDbArc" ); if (!result2.Success) { return(null, null); } // read angle 50 readerIn.ReadLine(); var startAngle = double.Parse(readerIn.ReadLine()); // read angle 60 readerIn.ReadLine(); var endAngle = double.Parse(readerIn.ReadLine()); var arc = new MarkGeometryArc( centrePoint, radius, // convert angle to radians GeometricArithmeticModule.ToRadians(startAngle), GeometricArithmeticModule.ToRadians(endAngle) ); return(layerName, arc); }
public Matrix4x4 ToMatrix4x4() { return(GeometricArithmeticModule.CombineTransformations( // apply scale GeometricArithmeticModule.GetScalingTransformationMatrix( ScaleX, ScaleY, ScaleZ ), // apply rotation - don't forget to convert degrees to radians GeometricArithmeticModule.GetRotationTransformationMatrix( GeometricArithmeticModule.ToRadians(RotationDegX), GeometricArithmeticModule.ToRadians(RotationDegY), GeometricArithmeticModule.ToRadians(RotationDegZ) ), // apply offset GeometricArithmeticModule.GetTranslationTransformationMatrix( OffsetX, OffsetY, OffsetZ ) )); }
public bool GenerateHatches(MHatchSettings settings) { HatchLines.Clear(); _totalHatchesJumpDistance = 0; _totalHatchesMarkDistance = 0; var lines = new List <MarkGeometryLine>(); var angleRad = GeometricArithmeticModule.ToRadians(settings.Angle); var size = Extents.Hypotenuse; var howmany = (int)Math.Ceiling(size / settings.Pitch); var yStart = Extents.Centre.Y - (0.5 * size); // generate lines to calculate intersections for hatch if (settings.Style == HatchStyle.RASTER || settings.Style == HatchStyle.RASTER_GRID) { for (int i = 0; i < howmany; i++) { double y = yStart + (i * settings.Pitch); var line = new MarkGeometryLine( new MarkGeometryPoint( -size + Extents.Centre.X, y ), new MarkGeometryPoint( size + Extents.Centre.X, y ) ); // apply angular rotation GeometricArithmeticModule.Rotate(line, 0, 0, angleRad, Extents.Centre.X, Extents.Centre.Y, Extents.Centre.Z); lines.Add(line); } } else if (settings.Style == HatchStyle.SERPENTINE || settings.Style == HatchStyle.SERPENTINE_GRID) { for (int i = 0; i < howmany; i++) { double y = yStart + (i * settings.Pitch); if (i % 2 == 0) { var line = new MarkGeometryLine( new MarkGeometryPoint( -size + Extents.Centre.X, y ), new MarkGeometryPoint( size + Extents.Centre.X, y ) ); // apply angular rotation GeometricArithmeticModule.Rotate(line, 0, 0, angleRad, Extents.Centre.X, Extents.Centre.Y, Extents.Centre.Z); lines.Add(line); } else { var line = new MarkGeometryLine( new MarkGeometryPoint( size + Extents.Centre.X, y ), new MarkGeometryPoint( -size + Extents.Centre.X, y ) ); // apply angular rotation GeometricArithmeticModule.Rotate(line, 0, 0, angleRad, Extents.Centre.X, Extents.Centre.Y, Extents.Centre.Z); lines.Add(line); } } } // duplicate lines if using grid var perpendicularAngleForGridLines = GeometricArithmeticModule.ToRadians(90); if (settings.Style == HatchStyle.RASTER_GRID || settings.Style == HatchStyle.SERPENTINE_GRID) { int startIndex = lines.Count - 1; for (int i = startIndex; i >= 0; i--) { var ln = (MarkGeometryLine)lines[i].Clone(); GeometricArithmeticModule.Rotate(ln, 0, 0, perpendicularAngleForGridLines, Extents.Centre.X, Extents.Centre.Y, Extents.Centre.Z); lines.Add(ln); } } // used to track jumps MarkGeometryPoint lastPoint = null; // generate hatch lines with extension for (int i = 0; i < lines.Count; i++) { List <MarkGeometryPoint> intersections = _contourQuadTree.Intersect(lines[i])?.ToList(); if (intersections == null) { continue; } int startIndex = (settings.Invert) ? 1 : 0; int endIndex = intersections.Count - 1; while (startIndex < endIndex) { var hatch = new MarkGeometryLine( intersections[startIndex], intersections[startIndex + 1] ); HatchLines.Add(hatch); // increase mark and jump distance if (lastPoint != null) { _totalHatchesJumpDistance += GeometricArithmeticModule.ABSMeasure2D( lastPoint, hatch.StartPoint ); } _totalHatchesMarkDistance += hatch.Length; lastPoint = hatch.EndPoint; startIndex += 2; } } return(true); }
public List <MarkGeometryPoint> ToPoints(double deviationToleranceDeg = 1) { if (IntersectionList.Count <= 0) { return(new List <MarkGeometryPoint>()); } else if (IntersectionList.Count <= 1) { return new List <MarkGeometryPoint> { ToPoint(IntersectionList.First.Value.ForwardEdgeIntersectionPoint) } } ; MVertex previousPoint = null; var lastEntry = IntersectionList.First; var points = new List <MarkGeometryPoint> { ToPoint(lastEntry.Value.ForwardEdgeIntersectionPoint) }; var current = lastEntry.Next; double referenceAngle = GetAngle( lastEntry.Value.ForwardEdgeIntersectionPoint, current.Value.ForwardEdgeIntersectionPoint ); deviationToleranceDeg = GeometricArithmeticModule.ToRadians(deviationToleranceDeg); while (current != null) { var angle = GetAngle( lastEntry.Value.ForwardEdgeIntersectionPoint, current.Value.ForwardEdgeIntersectionPoint ); if (Math.Abs(referenceAngle - angle) > deviationToleranceDeg) { lastEntry = current.Previous; points.Add(ToPoint(lastEntry.Value.ForwardEdgeIntersectionPoint)); referenceAngle = GetAngle( lastEntry.Value.ForwardEdgeIntersectionPoint, current.Value.ForwardEdgeIntersectionPoint ); } previousPoint = current.Value.ForwardEdgeIntersectionPoint; current = current.Next; } if (previousPoint != null) { points.Add(ToPoint(previousPoint)); } // close contour if closed, i.e. first edge touches last edge if (MSTLSlicer.CompareEqual(IntersectionList.First.Value.ForwardEdge, IntersectionList.Last.Value.BackwardEdge)) { points.Add(new MarkGeometryPoint(IntersectionList.First.Value.ForwardEdgeIntersectionPoint.X, IntersectionList.First.Value.ForwardEdgeIntersectionPoint.Y)); } return(points); }