/// <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(); }
public void addDxfDrawingEntry(DXFdrawingEntry in_DxfEntry) { AllDXFdrawingEntries.Add(in_DxfEntry); MyDxfBoundingBox obtainedDxfBoundingBox = in_DxfEntry.GetBoundingBox(); if (AllDXFdrawingEntries.Count > 1) { currentBoundingBox.XLowerLeft = currentBoundingBox.XLowerLeft < obtainedDxfBoundingBox.XLowerLeft ? currentBoundingBox.XLowerLeft : obtainedDxfBoundingBox.XLowerLeft; currentBoundingBox.YLowerLeft = currentBoundingBox.YLowerLeft < obtainedDxfBoundingBox.YLowerLeft ? currentBoundingBox.YLowerLeft : obtainedDxfBoundingBox.YLowerLeft; currentBoundingBox.XUpperRight = currentBoundingBox.XUpperRight > obtainedDxfBoundingBox.XUpperRight ? currentBoundingBox.XUpperRight : obtainedDxfBoundingBox.XUpperRight; currentBoundingBox.YUpperRight = currentBoundingBox.YUpperRight > obtainedDxfBoundingBox.YUpperRight ? currentBoundingBox.YUpperRight : obtainedDxfBoundingBox.YUpperRight; } else { currentBoundingBox = obtainedDxfBoundingBox; } }