Ejemplo n.º 1
0
 public MyDxfArc(double in_XCenter, double in_YCenter, double in_StartDegreeAngle, double in_EndDegreeAngle, double in_Radius, string in_Layer)
 {
     XCenter                   = in_XCenter;
     YCenter                   = in_YCenter;
     StartAngleRad             = MathHelperForTransformations.ConvertDegreesToRadians(in_StartDegreeAngle);
     StartAngleDegree          = in_StartDegreeAngle;
     EndAngleDegree            = in_EndDegreeAngle;
     EndAngleRad               = MathHelperForTransformations.ConvertDegreesToRadians(in_EndDegreeAngle);
     layerIdentifier           = in_Layer;
     doneTransformationOfAngle = false;
     if (EndAngleRad < StartAngleRad)
     {
         EndAngleRad += 2 * Math.PI;
         doneTransformationOfAngle = true;
     }
     Radius = in_Radius;
 }
Ejemplo n.º 2
0
        /// <summary>
        /// calculate bound box for arc
        /// </summary>
        /// <returns></returns>
        public override MyDxfBoundingBox GetBoundingBox()
        {
            //convert to ccw
            double alphaPrecomputedDegree = StartAngleDegree % 360;
            double alphaPrecomputedRad    = MathHelperForTransformations.ConvertDegreesToRadians(alphaPrecomputedDegree);
            double bethaPrecomputedDegree = EndAngleDegree % 360;
            double bethaPrecomputedRad    = MathHelperForTransformations.ConvertDegreesToRadians(bethaPrecomputedDegree);

            if (doneTransformationOfAngle)
            {
                bethaPrecomputedRad    += Math.PI * 2;
                bethaPrecomputedDegree += 360;
            }
            System.Diagnostics.Debug.Assert(alphaPrecomputedRad < 360);
            //arc endpoints
            double YZeroAlpha = YCenter + Radius * Math.Sin(alphaPrecomputedRad);
            double XZeroAlpha = XCenter + Radius * Math.Cos(alphaPrecomputedRad);
            double YZeroBetha = YCenter + Radius * Math.Sin(bethaPrecomputedRad);
            double XZeroBetha = XCenter + Radius * Math.Cos(bethaPrecomputedRad);
            //next, find all points on circle that divide it by 90 degrees (polar points, name it) between two angles defining the arc
            // https://stackoverflow.com/questions/1336663/2d-bounding-box-of-a-sector
            //maximum 4 points
            List <double> polarPointsXCoordinates = new List <double>();
            List <double> polarPointsYCoordinates = new List <double>();
            double        angularCounter          = Math.Ceiling(alphaPrecomputedDegree / 90) * 90;

            while (angularCounter < bethaPrecomputedDegree)
            {
                if ((angularCounter % 360 == 0) || (angularCounter == 0))
                {
                    polarPointsXCoordinates.Add(XCenter + Radius);
                    polarPointsYCoordinates.Add(YCenter);
                }
                else if (angularCounter % 270 == 0)
                {
                    polarPointsXCoordinates.Add(XCenter);
                    polarPointsYCoordinates.Add(YCenter - Radius);
                }
                else if (angularCounter % 180 == 0)
                {
                    polarPointsXCoordinates.Add(XCenter - Radius);
                    polarPointsYCoordinates.Add(YCenter);
                }
                else if (angularCounter % 90 == 0)
                {
                    polarPointsXCoordinates.Add(XCenter);
                    polarPointsYCoordinates.Add(YCenter + Radius);
                }
                angularCounter += 90;
            }
            MyDxfBoundingBox resultBox;
            List <double>    allPointsY = new List <double>();

            allPointsY.AddRange(polarPointsYCoordinates);
            allPointsY.Add(YZeroAlpha); allPointsY.Add(YZeroBetha);
            List <double> allPointsX = new List <double>();

            allPointsX.AddRange(polarPointsXCoordinates);
            allPointsX.Add(XZeroAlpha); allPointsX.Add(XZeroBetha);
            resultBox.YUpperRight = allPointsY.Max();
            resultBox.YLowerLeft  = allPointsY.Min();
            resultBox.XLowerLeft  = allPointsX.Min();
            resultBox.XUpperRight = allPointsX.Max();
            return(resultBox);
        }