public MyDxfArc(double in_XCenter, double in_YCenter, double in_StartDegreeAngle, double in_EndDegreeAngle, double in_Radius) { XCenter = in_XCenter; YCenter = in_YCenter; StartAngleRad = MathHelperForTransformations.ConvertDegreesToRadians(in_StartDegreeAngle); StartAngleDegree = in_StartDegreeAngle; EndAngleDegree = in_EndDegreeAngle; EndAngleRad = MathHelperForTransformations.ConvertDegreesToRadians(in_EndDegreeAngle); doneTransformationOfAngle = false; if (EndAngleRad < StartAngleRad) { EndAngleRad += 2 * Math.PI; doneTransformationOfAngle = true; } Radius = in_Radius; //calculate parameters required for drawing. C# arc has a weird definition //https://docs.microsoft.com/en-us/dotnet/api/system.drawing.graphics.drawarc drawStartAngleDegreeCW = in_StartDegreeAngle; double drawEndAngleDegreeCW = in_EndDegreeAngle != 0 ? in_EndDegreeAngle : 359.9999999999999999; if (drawEndAngleDegreeCW < drawStartAngleDegreeCW) { /* * double tmpAngle = drawStartAngleDegreeCW; * drawStartAngleDegreeCW = drawEndAngleDegreeCW; * drawEndAngleDegreeCW = tmpAngle; */ drawEndAngleDegreeCW += 360.0; } drawSweepAngleDegree = drawEndAngleDegreeCW - drawStartAngleDegreeCW; setupDrawingParameters(); }
/// <summary> /// rotate all entries in a structure around bounding box center point. Changes coordinates of them /// </summary> /// <param name="in_deg"></param> public void performRotationOfDxfStruct(double in_deg) { //obtain center of rotation double horizontalMidPoint = (this.currentBoundingBox.XLowerLeft + this.currentBoundingBox.XUpperRight) / 2.0; double verticalMidPoint = (this.currentBoundingBox.YLowerLeft + this.currentBoundingBox.YUpperRight) / 2.0; //obtain rotation matrix double[,] currentRotationMatrix = MathHelperForTransformations.getRotationMatrixAroundPoint(horizontalMidPoint, verticalMidPoint, MathHelperForTransformations.ConvertDegreesToRadians(in_deg)); //iterate over all entries in dxf structure altering them for (int iii = 0; iii < AllDXFdrawingEntries.Count; iii++) { DXFdrawingEntry item = AllDXFdrawingEntries[iii]; if (item is MyDxfLine) { Tuple <double, double> coord1 = MathHelperForTransformations.rotateImageUsingPrecalculatedTransformationMatrix(currentRotationMatrix, (item as MyDxfLine).XStart, (item as MyDxfLine).YStart); (item as MyDxfLine).XStart = coord1.Item1; (item as MyDxfLine).YStart = coord1.Item2; Tuple <double, double> coord2 = MathHelperForTransformations.rotateImageUsingPrecalculatedTransformationMatrix(currentRotationMatrix, (item as MyDxfLine).XEnd, (item as MyDxfLine).YEnd); (item as MyDxfLine).XEnd = coord2.Item1; (item as MyDxfLine).YEnd = coord2.Item2; } else if (item is MyDxfArc) { //center coordinates Tuple <double, double> coordCenter = MathHelperForTransformations.rotateImageUsingPrecalculatedTransformationMatrix(currentRotationMatrix, (item as MyDxfArc).XCenter, (item as MyDxfArc).YCenter); // Rotate start and stop angles. They are pointed by vectors, coming from Center and by magnitube of Radius // https://www.youtube.com/watch?v=g9lgL6f3h90 /* * double startAngleCoordinateX = (item as MyDxfArc).XCenter + (item as MyDxfArc).Radius * Math.Cos((item as MyDxfArc).StartAngleRad); * double startAngleCoordinateY = (item as MyDxfArc).YCenter + (item as MyDxfArc).Radius * Math.Sin((item as MyDxfArc).StartAngleRad); * double endAngleCoordinateX = (item as MyDxfArc).XCenter + (item as MyDxfArc).Radius * Math.Cos((item as MyDxfArc).EndAngleRad); * double endAngleCoordinateY = (item as MyDxfArc).YCenter + (item as MyDxfArc).Radius * Math.Sin((item as MyDxfArc).EndAngleRad); * //rotate vector which corresponds to start angle * Tuple<double, double> startAnglePointNew = MathHelperForTransformations.rotateImageUsingPrecalculatedTransformationMatrix(currentRotationMatrix, (startAngleCoordinateX ), (startAngleCoordinateY )); * double theta1Start = Math.Asin(Math.Abs(startAnglePointNew.Item2 - coordCenter.Item2) / (item as MyDxfArc).Radius); * double startAngleDegree = MathHelperForTransformations.ConvertRadiansToDegrees(theta1Start); * //rotate vector which corresponds to end angle * Tuple<double, double> endAnglePointNew = MathHelperForTransformations.rotateImageUsingPrecalculatedTransformationMatrix(currentRotationMatrix, (endAngleCoordinateX ), (endAngleCoordinateY )); * double theta2End = Math.Asin(Math.Abs(endAnglePointNew.Item2 - coordCenter.Item2) / (item as MyDxfArc).Radius); * double endAngleDegree = MathHelperForTransformations.ConvertRadiansToDegrees(theta2End); */ double startAngleDegree = (item as MyDxfArc).StartAngleDegree + in_deg; double endAngleDegree = (item as MyDxfArc).EndAngleDegree + in_deg; AllDXFdrawingEntries[iii] = new MyDxfArc(coordCenter.Item1, coordCenter.Item2, startAngleDegree, endAngleDegree, (item as MyDxfArc).Radius); } } //bounding box should be changed too. rotate ALL the coordinates of bounding rectangle and select the new appropriate values recalculateBoundingBoxFromScratch(); }