Ejemplo n.º 1
0
        //--------------------------------------------------------------------------------------------------

        public static Sketch CreateCircleWithArcs(double radius, int arcCount)
        {
            var sketch = Sketch.Create();
            var circle = new Geom2d_Circle(Ax2d.OX, radius);
            var step   = circle.Period() / (arcCount * 2);

            int startIndex = sketch.AddPoint(circle.Value(0));

            for (int i = 0; i < arcCount; i++)
            {
                int rimIndex = sketch.AddPoint(circle.Value(i * step * 2 + step));
                int endIndex = sketch.AddPoint(circle.Value((i + 1) * step * 2));
                sketch.AddSegment(new SketchSegmentArc(startIndex, endIndex, rimIndex));
                startIndex = endIndex;
            }
            sketch.MergePoints(startIndex, 0);

            Body.Create(sketch);
            return(sketch);
        }
Ejemplo n.º 2
0
        //--------------------------------------------------------------------------------------------------

        void _AddCircle(Geom2d_Circle circle, double first, double last)
        {
            if (Math.Abs(last - first) < circle.Period())
            {
                // Circle arc
                if (circle.Position().Sense() > 0)
                {
                    var temp = first;
                    first = last;
                    last  = temp;
                }

                var entity = new DxfDomCircle(_CurrentLayer, circle.Location(), circle.Radius(), circle.Value(first), circle.Value(last));
                _Document.Entities.Add(entity);
            }
            else
            {
                // Full circle
                var entity = new DxfDomCircle(_CurrentLayer, circle.Location(), circle.Radius());
                _Document.Entities.Add(entity);
            }
        }
Ejemplo n.º 3
0
        //--------------------------------------------------------------------------------------------------

        protected void AddCircle(Geom2d_Circle geom2DCircle, double first, double last, bool reverse)
        {
            if (Math.Abs(last - first) < geom2DCircle.Period())
            {
                // Circle arc
                var start = geom2DCircle.Value(reverse ? last : first);
                var end   = geom2DCircle.Value(reverse ? first : last);

                // Add the midpoint seems to be the simplest way to improve the BB
                BoundingBox?.Add(geom2DCircle.Value(first + (last - first) / 2));

                // Get parameters of circle
                double radius        = geom2DCircle.Radius();
                double length        = last - first;
                double halfParameter = (geom2DCircle.LastParameter() - geom2DCircle.FirstParameter()) / 2.0;
                var    size          = (length < halfParameter) ? SvgArcSize.Small : SvgArcSize.Large;
                var    sweep         = geom2DCircle.Position().Sense() > 0
                    ? (reverse ? SvgArcSweep.Negative : SvgArcSweep.Positive)
                    : (reverse ? SvgArcSweep.Positive : SvgArcSweep.Negative);

                AddToPath(new SvgPathSegArc(start, radius, radius, 0.0f, size, sweep, end));
            }
            else
            {
                // Complete circle
                var circleCenter = geom2DCircle.Location();
                var circleRadius = geom2DCircle.Radius();

                if (CombineToPath)
                {
                    if (geom2DCircle.Position().Sense() > 0)
                    {
                        reverse = !reverse;
                    }

                    ClosePath();
                    var rimPoints = new List <Pnt2d>(4)
                    {
                        new Pnt2d(circleCenter.X, circleCenter.Y + circleRadius),
                        new Pnt2d(circleCenter.X - circleRadius, circleCenter.Y),
                        new Pnt2d(circleCenter.X, circleCenter.Y - circleRadius),
                        new Pnt2d(circleCenter.X + circleRadius, circleCenter.Y),
                    };

                    SvgArcSweep sweep;
                    if (reverse)
                    {
                        rimPoints.Reverse();
                        sweep = SvgArcSweep.Positive;
                    }
                    else
                    {
                        sweep = SvgArcSweep.Negative;
                    }

                    AddToPath(new SvgPathSegArc(rimPoints[0], circleRadius, circleRadius, 45.0f, SvgArcSize.Small, sweep, rimPoints[1]));
                    AddToPath(new SvgPathSegArc(rimPoints[1], circleRadius, circleRadius, 45.0f, SvgArcSize.Small, sweep, rimPoints[2]));
                    AddToPath(new SvgPathSegArc(rimPoints[2], circleRadius, circleRadius, 45.0f, SvgArcSize.Small, sweep, rimPoints[3]));
                    AddToPath(new SvgPathSegArc(rimPoints[3], circleRadius, circleRadius, 45.0f, SvgArcSize.Small, sweep, rimPoints[0]));
                    ClosePath();
                }
                else
                {
                    CurrentGroup.Children.Add(new SvgCircleElement(circleCenter, circleRadius));
                }

                // Enlarge BB
                var f = geom2DCircle.FirstParameter();
                var q = (geom2DCircle.LastParameter() - f) / 4;
                BoundingBox?.Add(geom2DCircle.Value(f));
                BoundingBox?.Add(geom2DCircle.Value(f + q));
                BoundingBox?.Add(geom2DCircle.Value(f + q * 2));
                BoundingBox?.Add(geom2DCircle.Value(f + q * 3));
            }
        }