Example #1
0
        /***************************************************/
        /****          Split curve at points            ****/
        /***************************************************/

        public static List <Arc> SplitAtPoints(this Arc arc, List <Point> points, double tolerance = Tolerance.Distance)
        {
            if (!points.Any())
            {
                return new List <Arc> {
                           arc.Clone()
                }
            }
            ;

            List <Arc>   result = new List <Arc>();
            List <Point> cPts   = new List <Point>();
            Vector       normal = arc.Normal();

            foreach (Point point in points)
            {
                if (point.IsOnCurve(arc, tolerance))
                {
                    cPts.Add(point);
                }
            }

            cPts.Add(arc.StartPoint());
            cPts.Add(arc.EndPoint());
            cPts = cPts.CullDuplicates(tolerance);
            cPts = cPts.SortAlongCurve(arc, tolerance);

            if (arc.EndAngle - 2 * Math.PI < tolerance && arc.EndAngle - 2 * Math.PI > -tolerance)
            {
                cPts.Add(arc.EndPoint());
            }

            if (cPts.Count > 2)
            {
                Double startAng = arc.StartAngle;
                Double endAng   = arc.EndAngle;
                Double tmpAng   = 0;
                Arc    tmpArc;

                for (int i = 1; i < cPts.Count; i++)
                {
                    tmpArc = arc.Clone();

                    tmpArc.StartAngle = startAng;
                    tmpAng            = (2 * Math.PI + (cPts[i - 1] - arc.Centre()).SignedAngle(cPts[i] - arc.Centre(), normal)) % (2 * Math.PI);
                    endAng            = startAng + tmpAng;
                    tmpArc.EndAngle   = endAng;
                    result.Add(tmpArc);
                    startAng = endAng;
                }
            }
            else
            {
                result.Add(arc.Clone());
            }
            return(result);
        }
Example #2
0
        public override Visual Clone()
        {
            var copy = new VisualArc(_arc.Clone() as Arc);

            copy.Prototype(this);
            return(copy);
        }
Example #3
0
 public OffsetArc(Entity entity)
     : base()
 {
     _arc = entity as Arc;
     if (_arc != null)
     {
         _result = _arc.Clone() as Arc;
     }
 }
Example #4
0
        private Grid CreateArcGridAxis(Document doc, Arc curve)
        {
            if (doc == null || curve == null)
            {
                return(null);
            }

            if (curve.IsBound)
            {
                return(Grid.Create(doc, curve));
            }

            // Create almost-closed grid line.
            Arc copyCurve = curve.Clone() as Arc;

            copyCurve.MakeBound(0, 2 * Math.PI * (359.0 / 360.0));
            return(Grid.Create(doc, copyCurve));
        }
Example #5
0
            protected override void WorkCompleted(Environment model)
            {
                model.Entities.Add(toolPath, "Default", Color.DarkBlue);

                #region Tool symbol definition

                Block b1 = new Block("ballTool");

                Circle c1 = new Circle(0, 0, 0, ballToolRadius);
                Circle c2 = new Circle(0, 0, 50, ballToolRadius);
                Arc    a1 = new Arc(0, 0, 0, ballToolRadius, Math.PI, 2 * Math.PI);
                a1.Rotate(Math.PI / 2, Vector3D.AxisX);
                Arc a2 = (Arc)a1.Clone();
                a2.Rotate(Math.PI / 2, Vector3D.AxisZ);

                Line l1 = new Line(-ballToolRadius, 0, 0, -ballToolRadius, 0, 50);

                b1.Entities.Add(c1);
                b1.Entities.Add(c2);
                b1.Entities.Add(a1);
                b1.Entities.Add(a2);
                b1.Entities.Add(l1);

                LinearPath lp1 = LinearPath.CreateHelix(ballToolRadius, 50, 1, false, .1);
                b1.Entities.Add(lp1);

                b1.Entities.Add(lp1);
                for (int i = 1; i < 4; i++)
                {
                    Line cloneLn = (Line)l1.Clone();
                    cloneLn.Rotate(i * Math.PI / 2, Vector3D.AxisZ);
                    b1.Entities.Add(cloneLn);
                }

                model.Blocks.Add(b1);

                #endregion

                // Adds a reference to the tool symbol
                model.Entities.Add(new BlockReference(toolPath.Vertices[toolPath.Vertices.Length - 1], "ballTool", 1, 1, 1, 0));

                model.ZoomFit();
            }
Example #6
0
        private Grid CreateArcGridAxis(Document doc, Arc curve)
        {
            if (doc == null || curve == null)
            {
                return(null);
            }

            Arc curveToUse = null;

            if (!curve.IsBound)
            {
                // Create almost-closed grid line.
                curveToUse = curve.Clone() as Arc;
                curveToUse.MakeBound(0, 2 * Math.PI * (359.0 / 360.0));
            }
            else
            {
                curveToUse = curve;
            }

            return(CreateGridFromCurve(doc, curveToUse));
        }
Example #7
0
        public static Arc Offset(this Arc curve, double offset, Vector normal, bool tangentExtensions = false, double tolerance = Tolerance.Distance)
        {
            if (offset == 0)
            {
                return(curve);
            }

            double radius = curve.Radius;

            if (normal == null)
            {
                normal = curve.Normal();
            }

            if (normal.DotProduct(curve.Normal()) > 0)
            {
                radius += offset;
            }
            else
            {
                radius -= offset;
            }

            Arc result = curve.Clone();

            if (radius > 0)
            {
                result.Radius = radius;
                return(result);
            }
            else
            {
                Reflection.Compute.RecordError("Offset value is greater than arc radius");
                return(null);
            }
        }
        /***************************************************/

        private static IEnumerable <ICurve> SplitAtX(Arc arc, double x, double tol = Tolerance.Distance)
        {
            // Assumes 2D
            List <ICurve> results = new List <ICurve>();

            if (IntersectsArc(arc, x, tol))
            {
                Point centre = arc.CoordinateSystem.Origin;
                results.AddRange(SplitAtX(new Circle()
                {
                    Centre = centre, Radius = arc.Radius
                }, x, tol));
                Point  start      = arc.StartPoint();
                Point  end        = arc.EndPoint();
                double startAngle = Vector.XAxis.SignedAngle(start - centre, Vector.ZAxis);
                double endAngle   = Vector.XAxis.SignedAngle(end - centre, Vector.ZAxis);
                bool   flip       = false;

                if ((start - centre).CrossProduct(arc.StartDir()).Z < 0)
                {
                    double temp = startAngle;
                    startAngle = endAngle;
                    endAngle   = temp;
                    Point tempPt = start;
                    start = end;
                    end   = tempPt;

                    flip = true;
                }
                double pi2 = Math.PI * 2;
                if (start.X > x)
                {
                    Arc toSplit = (Arc)results[1];
                    results.RemoveAt(1);
                    if (end.X > x)
                    {
                        // Both to the right
                        results.Insert(0, Geometry.Create.Arc(toSplit.CoordinateSystem, arc.Radius, startAngle, toSplit.EndAngle < startAngle ? toSplit.EndAngle + pi2 : toSplit.EndAngle));
                        results.Add(Geometry.Create.Arc(toSplit.CoordinateSystem, arc.Radius, toSplit.StartAngle, endAngle < toSplit.StartAngle ? endAngle + pi2 : endAngle));
                    }
                    else
                    {
                        results.RemoveAt(0);
                        // start right, end left
                        results.Add(Geometry.Create.Arc(toSplit.CoordinateSystem, arc.Radius, startAngle, toSplit.EndAngle < startAngle ? toSplit.EndAngle + pi2 : toSplit.EndAngle));
                        results.Add(Geometry.Create.Arc(toSplit.CoordinateSystem, arc.Radius, toSplit.EndAngle, endAngle < toSplit.EndAngle ? endAngle + pi2 : endAngle));
                    }
                }
                else
                {
                    Arc toSplit = (Arc)results[0];
                    results.RemoveAt(0);
                    if (end.X > x)
                    {
                        results.RemoveAt(0);
                        // start left, end right
                        results.Add(Geometry.Create.Arc(toSplit.CoordinateSystem, arc.Radius, startAngle + pi2 < toSplit.EndAngle ? startAngle + pi2 : startAngle, toSplit.EndAngle));
                        results.Add(Geometry.Create.Arc(toSplit.CoordinateSystem, arc.Radius, toSplit.EndAngle, endAngle < toSplit.EndAngle ? endAngle + pi2 : endAngle));
                    }
                    else
                    {
                        // both left
                        results.Insert(0, Geometry.Create.Arc(toSplit.CoordinateSystem, arc.Radius, startAngle + pi2 < toSplit.EndAngle ? startAngle + pi2 : startAngle, toSplit.EndAngle));
                        results.Add(Geometry.Create.Arc(toSplit.CoordinateSystem, arc.Radius, toSplit.StartAngle, endAngle < toSplit.StartAngle ? endAngle + pi2 : endAngle));
                    }
                }

                // Flip test
                if (flip)
                {
                    results = results.Select(y => y.IFlip()).Reverse().ToList();
                }
            }
            else
            {
                results.Add(arc.Clone());
            }

            return(results);
        }
Example #9
0
        /***************************************************/


        public static List <Arc> SplitAtPoints(this Circle circle, List <Point> points, double tolerance = Tolerance.Distance)
        {
            List <Arc>   result = new List <Arc>();
            List <Point> cPts   = new List <Point>();

            foreach (Point point in points)
            {
                if (point.IsOnCurve(circle, tolerance))
                {
                    cPts.Add(point);
                }
            }

            cPts = cPts.CullDuplicates(tolerance);
            cPts = cPts.SortAlongCurve(circle);

            Point     cirCen      = circle.Centre;
            Vector    startVector = circle.StartPoint() - circle.Centre;
            Vector    normal      = circle.Normal;
            Double    rotAng;
            Cartesian system  = new Cartesian(circle.Centre, startVector.Normalise(), (circle.PointAtParameter(0.25) - cirCen).Normalise(), normal);
            Arc       mainArc = new Arc();
            Arc       tmpArc  = new Arc();

            mainArc.CoordinateSystem = system;
            mainArc.Radius           = circle.Radius;

            Vector stVec;
            Vector enVec;
            Double enAng;

            if (cPts.Count == 1)
            {
                tmpArc = mainArc;
                stVec  = cPts[0] - circle.Centre;
                rotAng = ((2 * Math.PI + startVector.SignedAngle(stVec, normal)) % (2 * Math.PI));
                enAng  = 2 * Math.PI;

                tmpArc            = tmpArc.Rotate(cirCen, normal, rotAng);
                tmpArc.StartAngle = 0;
                tmpArc.EndAngle   = enAng;
                result.Add(tmpArc.Clone());
            }
            else
            {
                for (int i = 0; i < cPts.Count; i++)
                {
                    tmpArc = mainArc;
                    stVec  = cPts[i] - circle.Centre;
                    enVec  = cPts[(i + 1) % cPts.Count] - circle.Centre;
                    rotAng = ((2 * Math.PI + startVector.SignedAngle(stVec, normal)) % (2 * Math.PI));
                    enAng  = ((2 * Math.PI + stVec.SignedAngle(enVec, normal)) % (2 * Math.PI));

                    tmpArc            = tmpArc.Rotate(cirCen, normal, rotAng);
                    tmpArc.StartAngle = 0;
                    tmpArc.EndAngle   = enAng;
                    result.Add(tmpArc.Clone());
                }
            }
            return(result);
        }
      private Grid CreateArcGridAxis(Document doc, Arc curve)
      {
         if (doc == null || curve == null)
            return null;

         if (curve.IsBound)
            return Grid.Create(doc, curve);

         // Create almost-closed grid line.
         Arc copyCurve = curve.Clone() as Arc;
         copyCurve.MakeBound(0, 2 * Math.PI * (359.0 / 360.0));
         return Grid.Create(doc, copyCurve);
      }