示例#1
0
            /// <summary>
            /// Build arc by 3 given points
            /// ( the inside CS will centered in the arc center and Xaxis toward p1 )
            /// </summary>
            public Arc3D(double tol_len, Vector3D p1, Vector3D p2, Vector3D p3, Vector3D normal = null) :
                base(GeometryType.Arc3D)
            {
                Type = GeometryType.Arc3D;

                var nfo = Arc3D.CircleBy3Points(p1, p2, p3);

                CS     = nfo.CS;
                Radius = nfo.Radius;

                if (normal != null)
                {
                    if (!normal.Colinear(tol_len, CS.BaseZ))
                    {
                        throw new Exception($"invalid given normal not colinear to arc axis");
                    }
                    if (!normal.Concordant(tol_len, CS.BaseZ))
                    {
                        CS = CS.Rotate(CS.BaseX, PI);
                    }
                }

                AngleStartRad = CS.BaseX.AngleToward(tol_len, p1 - CS.Origin, CS.BaseZ);
                AngleEndRad   = CS.BaseX.AngleToward(tol_len, p3 - CS.Origin, CS.BaseZ);
            }
示例#2
0
        public void Arc3DTest_002()
        {
            var p1 = new Vector3D(20.175, 178.425, -56.314);
            var p2 = new Vector3D(1.799, 231.586, -18.134);
            var p3 = new Vector3D(262.377, 302.118, 132.195);

            var c  = Arc3D.CircleBy3Points(p1, p2, p3);
            var cs = c.CS;

            // verify points contained in arc plane
            Assert.True(cs.Contains(1e-3, p1));
            Assert.True(cs.Contains(1e-3, p2));
            Assert.True(cs.Contains(1e-3, p3));

            // cscad retrieved from cad using ucs align entity
            var cscad = new CoordinateSystem3D(new Vector3D(165.221, 214.095, 24.351),
                                               new Vector3D(-0.259, -0.621, 0.74), CoordinateSystem3DAutoEnum.AAA);

            // assert cs and cscad are coplanar with same origin
            Assert.True(cscad.Origin.EqualsTol(1e-3, cs.Origin));
            Assert.True((cscad.BaseX + cs.Origin).ToUCS(cs).Z.EqualsTol(1e-3, 0));
            Assert.True((cscad.BaseY + cs.Origin).ToUCS(cs).Z.EqualsTol(1e-3, 0));

            Assert.True(c.Radius.EqualsTol(1e-3, 169.758));

            // create a circle through p1,p2,p3 and states if the same as arc by 3 points
            var c2 = new Circle3D(p1, p2, p3);

            Assert.True(c.Radius.EqualsAutoTol(c2.Radius));
            Assert.True(c.CS.Origin.EqualsAutoTol(c2.CS.Origin));
            Assert.True(c.CS.IsParallelTo(1e-3, c2.CS));
        }
示例#3
0
        public void Arc3DTest_0001()
        {
            var tol = 1e-7;

            var p1 = new Vector3D("X = 13.87329226 Y = 134.93466652 Z = -3.70729037");
            var p2 = new Vector3D("X = 75.89230418 Y = 224.11406806 Z = 35.97437873");
            var p3 = new Vector3D("X = 97.48181688 Y = 229.31008314 Z = 16.9314998");

            var arc = new Arc3D(tol, p1, p2, p3);

            var plo = new Vector3D("X = -74.96786784 Y = 178.50832685 Z = -43.45380285");
            var plx = new Vector3D("X = 61.65932598 Y = 313.82398026 Z = -33.75931542");
            var ply = new Vector3D("X = 87.35160811 Y = 8.94741958 Z = 35.66234059");

            var plcs = new CoordinateSystem3D(plo, plx - plo, ply - plo);

            var iSegmentPts = arc.Intersect(tol, plcs, only_perimeter: false).ToList();
            var i1          = iSegmentPts[0];
            var i2          = iSegmentPts[1];
            var iSegment    = new Line3D(i1, i2);

            Assert.True(plcs.Contains(tol, i1));
            Assert.True(plcs.Contains(tol, i2));

            Assert.True(arc.Contains(tol, i1, onlyPerimeter: false));
            Assert.True(arc.Contains(tol, i2, onlyPerimeter: false));

            Assert.True(i1.EqualsTol(tol, new Vector3D("X = 40.09735573 Y = 156.48945821 Z = -7.46179105")));
            Assert.True(i2.EqualsTol(tol, new Vector3D("X = 72.20796391 Y = 188.29182351 Z = -5.18335819")));
        }
示例#4
0
            /// <summary>
            /// Build arc by 3 given points with angle 2*PI
            /// ( the inside CS will centered in the arc center and Xaxis toward p1 )
            /// </summary>
            internal Arc3D(Vector3D p1, Vector3D p2, Vector3D p3) :
                base(GeometryType.Arc3D)
            {
                Type = GeometryType.Arc3D;

                var nfo = Arc3D.CircleBy3Points(p1, p2, p3);

                CS     = nfo.CS;
                Radius = nfo.Radius;

                AngleStartRad = 0;
                AngleEndRad   = 2 * PI;
            }
示例#5
0
        /// <summary>
        /// todo _ Testare questo metodo con varibili varie
        /// </summary>
        /// <param name="arc3D"></param>
        /// <param name="feed"></param>
        /// <returns></returns>
        internal static TimeSpan CalcTime(Arc3D arc3D, double feed)
        {
            var lunghezza = arc3D.GetLength();

            if (feed == 0)
            {
                return(new TimeSpan());
            }

            var minuti = lunghezza / feed;

            return(TimeSpan.FromMinutes(minuti));
        }
示例#6
0
        static void Main(string[] args)
        {
            var tol = 1e-8;
            var R   = 100;

            var dxf     = new netDxf.DxfDocument();
            var ang     = 0d;
            var angStep = 10d.ToRad();
            var angElev = 20d.ToRad();

            var o = Vector3D.Zero;
            var p = new Vector3D(R, 0, 0);

            Circle3D circ = null;

            while (ang < 2 * PI)
            {
                var l     = new Line3D(o, p.RotateAboutZAxis(ang));
                var l_ent = l.DxfEntity;
                l_ent.Color = netDxf.AciColor.Cyan;
                dxf.AddEntity(l_ent);

                var arcCS   = new CoordinateSystem3D(o, l.V, Vector3D.ZAxis);
                var arc     = new Arc3D(tol, arcCS, R, 0, angElev);
                var arc_ent = arc.DxfEntity;
                arc_ent.Color = netDxf.AciColor.Yellow;
                dxf.AddEntity(arc_ent);

                var arc2CS = new CoordinateSystem3D(l.To - R * Vector3D.ZAxis,
                                                    Vector3D.ZAxis, Vector3D.Zero - l.To);
                var arc2     = new Arc3D(tol, arc2CS, R, 0, PI / 2);
                var arc2_ent = arc2.DxfEntity;
                arc2_ent.Color = netDxf.AciColor.Green;
                dxf.AddEntity(arc2_ent);

                if (circ == null)
                {
                    circ = new Circle3D(tol,
                                        CoordinateSystem3D.WCS.Move(Vector3D.ZAxis * arc.To.Z),
                                        arc.To.Distance2D(Vector3D.Zero));
                    var circ_ent = circ.DxfEntity;
                    circ_ent.Color = netDxf.AciColor.Yellow;
                    dxf.AddEntity(circ_ent);
                }

                ang += angStep;
            }

            dxf.Viewport.ShowGrid = false;
            dxf.Save("output.dxf", isBinary: true);
        }
示例#7
0
        public void Arc3DTest_008()
        {
            var tol = 1e-7;

            var p1  = new Vector3D(20.17459383, 178.42487311, -56.31435851);
            var p2  = new Vector3D(1.7990927, 231.58612295, -18.13420814);
            var p3  = new Vector3D(262.37695212, 302.11773752, 132.19450446);
            var arc = new Arc3D(tol, p1, p2, p3);

            var dp1  = new Vector3D("X = 4.11641325 Y = 266.06066703 Z = 11.60392802");
            var dp2  = new Vector3D("X = 58.22323201 Y = 331.06393108 Z = 85.07377904");
            var dp3  = new Vector3D("X = 158.93019908 Y = 345.12414417 Z = 132.0972665");
            var dp4  = new Vector3D("X = 62.63561614 Y = 268.87580225 Z = 34.43511732");
            var dp4_ = new Vector3D("X = 16.03656748 Y = 293.76000567 Z = 39.01589812");

            Action <Arc3D, Vector3D, Vector3D> test = (subarc, ap1, ap2) =>
            {
                Assert.True(arc.CS.Origin.EqualsTol(tol, subarc.CS.Origin));
                Assert.True(arc.CS.IsParallelTo(tol, subarc.CS));
                Assert.True(subarc.From.EqualsTol(tol, ap1));
                Assert.True(subarc.To.EqualsTol(tol, ap2));
            };

            Assert.True(arc.Split(tol, null).Count() == 0);
            Assert.True(arc.Split(tol, new Vector3D[] { }).Count() == 0);
            Assert.True(arc.Split(tol, new[] { dp1, dp2, dp3, dp4, arc.From, arc.To }).Count() == 5);

            {
                var dps     = new[] { dp1, dp2, dp3, dp4 };
                var subarcs = arc.Split(tol, dps).ToList();
                Assert.True(subarcs.Count == 5);

                test(subarcs[0], arc.From, dp1);
                test(subarcs[1], dp1, dp4_);
                test(subarcs[2], dp4_, dp2);
                test(subarcs[3], dp2, dp3);
                test(subarcs[4], dp3, arc.To);
            }

            {
                var dps     = new[] { dp1, dp2, dp3, dp4 };
                var subarcs = arc.Split(tol, dps, validate_pts: true).ToList();
                Assert.True(subarcs.Count == 4);

                test(subarcs[0], arc.From, dp1);
                test(subarcs[1], dp1, dp2);
                test(subarcs[2], dp2, dp3);
                test(subarcs[3], dp3, arc.To);
            }
        }
示例#8
0
        public void Arc3DTest_004()
        {
            var p1 = new Vector3D(20.175, 178.425, -56.314);
            var p2 = new Vector3D(1.799, 231.586, -18.134);
            var p3 = new Vector3D(262.377, 302.118, 132.195);

            var c  = Arc3D.CircleBy3Points(p1, p2, p3);
            var cs = c.CS;

            var wrongNormal = new Vector3D(9.998, .175, 0);
            var csok        = new Arc3D(1e-3, p1, p2, p3, cs.BaseZ);

            Assert.Throws <ArgumentException>(new System.Action(() => new Arc3D(1e-3, p1, p2, p3, wrongNormal)));
        }
示例#9
0
 /// <summary>
 /// Checks if two arcs are equals ( it checks agains swapped from-to too )
 /// </summary>
 public bool EqualsTol(double tolLen, double tolRad, Arc3D other)
 {
     if (!Center.EqualsTol(tolLen, other.Center))
     {
         return(false);
     }
     if (!Radius.EqualsTol(tolLen, other.Radius))
     {
         return(false);
     }
     if (!Segment.EqualsTol(tolLen, other.Segment))
     {
         return(false);
     }
     return(true);
 }
示例#10
0
            /// <summary>
            /// create a set of subarc from this by splitting through given split points
            /// split point are not required to be on perimeter of the arc ( a center arc to point line will split )
            /// generated subarcs will start from this arc angleFrom and contiguosly end to angleTo
            /// </summary>
            /// <param name="tol_len">arc length tolerance</param>
            /// <param name="_splitPts">point where split arc</param>
            /// <param name="validate_pts">if true split only for split points on arc perimeter</param>
            public IEnumerable <Arc3D> Split(double tol_len, IEnumerable <Vector3D> _splitPts, bool validate_pts = false)
            {
                var tol_rad = tol_len.RadTol(Radius);

                if (_splitPts == null || _splitPts.Count() == 0)
                {
                    yield break;
                }

                IEnumerable <Vector3D> splitPts = _splitPts;

                if (validate_pts)
                {
                    splitPts = _splitPts.Where(pt => Contains(tol_len, pt, onlyPerimeter: true)).ToList();
                }

                var radCmp = new DoubleEqualityComparer(tol_rad);

                var hs_angles_rad = new HashSet <double>(radCmp);

                foreach (var splitPt in splitPts.Select(pt => PtAngle(tol_len, pt)))
                {
                    if (PtAtAngle(splitPt).EqualsTol(tol_len, From) || PtAtAngle(splitPt).EqualsTol(tol_len, To))
                    {
                        continue;
                    }
                    hs_angles_rad.Add(splitPt.NormalizeAngle2PI(tol_rad));
                }

                var angles_rad = hs_angles_rad.OrderBy(w => w).ToList();

                if (!hs_angles_rad.Contains(AngleStart))
                {
                    angles_rad.Insert(0, AngleStart);
                }
                if (!hs_angles_rad.Contains(AngleEnd))
                {
                    angles_rad.Add(AngleEnd);
                }

                for (int i = 0; i < angles_rad.Count - 1; ++i)
                {
                    var arc = new Arc3D(tol_len, CS, Radius, angles_rad[i], angles_rad[i + 1]);
                    yield return(arc);
                }
            }
示例#11
0
        public void Arc3DTest_005()
        {
            var p1 = new Vector3D(20.17459383, 178.42487311, -56.31435851);
            var p2 = new Vector3D(1.7990927, 231.58612295, -18.13420814);
            var p3 = new Vector3D(262.37695212, 302.11773752, 132.19450446);

            var c = new Arc3D(1e-3, p1, p2, p3);

            Assert.True(new Line3D(c.Center, c.CS.BaseX, Line3DConstructMode.PointAndVector)
                        .SemiLineContainsPoints(1e-3, p1));
            var radTol = (1e-1).RadTol(c.Radius);
            var degTol = radTol.ToDeg();

            {
                var cinverse = new Arc3D(1e-3, p3, p2, p1);
                Assert.True(new Line3D(c.Center, cinverse.CS.BaseX, Line3DConstructMode.PointAndVector)
                            .SemiLineContainsPoints(1e-3, p3));
                Assert.True(c.AngleStart.EqualsTol(radTol, cinverse.AngleStart));
                Assert.True(c.AngleEnd.EqualsTol(radTol, cinverse.AngleEnd));
            }

            Assert.True(c.AngleStart.ToDeg().EqualsTol(degTol, 0));
            Assert.True(c.AngleEnd.ToDeg().EqualsTol(degTol, 154.14));

            var moveVector = new Vector3D(-1998.843, -6050.954, -1980.059);
            var cmoved     = c.Move(1e-3, moveVector);

            var p1moved = p1 + moveVector;
            var p2moved = p2 + moveVector;
            var p3moved = p3 + moveVector;

            Assert.True(cmoved.Contains(1e-3, p1moved, onlyPerimeter: true));
            Assert.True(cmoved.Contains(1e-3, p2moved, onlyPerimeter: true));
            Assert.True(cmoved.Contains(1e-3, p3moved, onlyPerimeter: true));

            Assert.True(c.Angle.ToDeg().EqualsTol(degTol, 154.14));

            var c2 = new Arc3D(1e-3, c.CS, c.Radius, c.AngleEnd, c.AngleStart);

            Assert.True(c2.Angle.ToDeg().EqualsTol(degTol, 360d - 154.14));

            Assert.True(c.Length.EqualsTol(1e-3, 456.67959116));
        }
示例#12
0
        public void Arc3DTest_003()
        {
            var p1 = new Vector3D(20.175, 178.425, -56.314);
            var p2 = new Vector3D(1.799, 231.586, -18.134);
            var p3 = new Vector3D(262.377, 302.118, 132.195);

            var c  = Arc3D.CircleBy3Points(p1, p2, p3);
            var cs = c.CS;

            var arc   = new Arc3D(1e-3, p1, p2, p3, -cs.BaseZ);
            var arcCs = arc.CS;

            // two cs share same origin
            Assert.True(arc.CS.Origin.EqualsTol(1e-3, cs.Origin));
            // two cs with discordant colinear Z
            Assert.True(arc.CS.BaseZ.Colinear(1e-3, cs.BaseZ) && !arc.CS.BaseZ.Concordant(1e-3, cs.BaseZ));
            // two cs parallel
            Assert.True(arc.CS.IsParallelTo(1e-3, cs));
        }
示例#13
0
        public void Arc3DTest_006()
        {
            var tol = 1e-7;

            var p1  = new Vector3D(20.17459383, 178.42487311, -56.31435851);
            var p2  = new Vector3D(1.7990927, 231.58612295, -18.13420814);
            var p3  = new Vector3D(262.37695212, 302.11773752, 132.19450446);
            var arc = new Arc3D(tol, p1, p2, p3);

            // area and centre of mass
            var A        = 0d;
            var centroid = arc.CentreOfMass(out A);

            Assert.True(A.EqualsTol(1e-7, 32476.83673649));
            Assert.True(centroid.EqualsTol(1e-7, new Vector3D("X=106.62109106 Y=278.15563166 Z=57.60718457")));

            var dp1 = new Vector3D("X = 4.11641325 Y = 266.06066703 Z = 11.60392802");
            var dp2 = new Vector3D("X = 58.22323201 Y = 331.06393108 Z = 85.07377904");
            var dp3 = new Vector3D("X = 158.93019908 Y = 345.12414417 Z = 132.0972665");
            {
                var q = arc.Divide(4, include_endpoints: true).ToList();
                Assert.True(q.Count == 3 + 2);
                Assert.True(q.Any(w => w.EqualsTol(tol, p1)));
                Assert.True(q.Any(w => w.EqualsTol(tol, dp1)));
                Assert.True(q.Any(w => w.EqualsTol(tol, dp2)));
                Assert.True(q.Any(w => w.EqualsTol(tol, dp3)));
                Assert.True(q.Any(w => w.EqualsTol(tol, p3)));
            }

            // bbox
            var bbox = arc.BBox(tol);

            Assert.True(bbox.Contains(tol, new Vector3D("X = 1.24800294 Y = 178.42487311 Z = -56.31435851")));
            Assert.True(bbox.Contains(tol, new Vector3D("X = 262.37695212 Y = 178.42487311 Z = -56.31435851")));
            Assert.True(bbox.Contains(tol, new Vector3D("X = 262.37695212 Y = 347.16710407 Z = -56.31435851")));
            Assert.True(bbox.Contains(tol, new Vector3D("X = 1.24800294 Y = 347.16710407 Z = -56.31435851")));
            Assert.True(bbox.Contains(tol, new Vector3D("X = 1.24800294 Y = 178.42487311 Z = 138.54160976")));
            Assert.True(bbox.Contains(tol, new Vector3D("X = 262.37695212 Y = 178.42487311 Z = 138.54160976")));
            Assert.True(bbox.Contains(tol, new Vector3D("X = 262.37695212 Y = 347.16710407 Z = 138.54160976")));
            Assert.True(bbox.Contains(tol, new Vector3D("X = 1.24800294 Y = 347.16710407 Z = 138.54160976")));
        }
示例#14
0
        protected override List <IEntity3D> GetFinalPreview()
        {
            var rslt = new List <IEntity3D>();

            if (PatternDrilling != null)
            {
                var diameter = DiametroPreview;// fare proprieta comuine iun modo da personalizzare diametro per ogni lavorazione

                if (diameter == 0)
                {
                    diameter = 1;
                }

                var pntList = PatternDrilling.GetPointList();

                foreach (var point2D in pntList)
                {
                    var arc = new Arc3D {
                        Radius = diameter / 2, Center = new Point3D(point2D.X, point2D.Y, 0)
                    };

                    arc.Start = new Point3D(arc.Center);

                    arc.Start.X += arc.Radius;

                    arc.End = new Point3D(arc.Center);

                    arc.End.X += arc.Radius;

                    rslt.Add(arc);
                }
            }

            foreach (var entity2D in rslt)
            {
                entity2D.PlotStyle = EnumPlotStyle.Element;
            }

            return(rslt);
        }
示例#15
0
        public void Arc3DTest()
        {
            var o  = new Vector3D(4.4249, 1.0332, -3.7054);
            var cs = new CoordinateSystem3D(o,
                                            new Vector3D(-.1201, 4.4926, 1.4138),
                                            new Vector3D(-1.6282, 3.2952, 2.1837));

            var r     = 4.2753;
            var ang1  = 26.10878d.ToRad();
            var ange2 = 63.97731d.ToRad();
            var arc   = new Arc3D(cs, r, ang1, ange2);

            var seg_i   = new Line3D(2.2826, 10.2516, -3.7469, 1.3767, -3.7709, 1.5019);
            var ip_circ = arc.Intersect(1e-4, seg_i);
            var ip_arc  = arc.IntersectArc(1e-2, rad_tol, seg_i);

            // aegment intersecting arc
            Assert.True(ip_circ.Count() == 1);
            Assert.True(ip_circ.First().EqualsTol(1e-4, ip_arc.First()));
            Assert.True(ip_circ.First().EqualsTol(1e-2, 1.83, 3.24, -1.12));

            // segment not intersecting arc
            var seg_i2 = seg_i.Scale(seg_i.From, .3);

            Assert.True(arc.Intersect(1e-4, seg_i2, segment_mode: true).Count() == 0);
            Assert.True(arc.IntersectArc(1e-4, rad_tol, seg_i2, segment_mode: true).Count() == 0);

            // segment not intersecting, but line intersecting arc
            Assert.True(arc.Intersect(1e-4, seg_i2).Count() == 1);
            Assert.True(arc.Intersect(1e-4, seg_i2).First().EqualsTol(1e-4, ip_arc.First()));

            // segment intresecting circle, but not arc
            var seg_e = new Line3D(2.4523, 9.6971, -1.8004, 4.6142, -.0631, -2.0519);

            Assert.True(arc.Intersect(1e-4, seg_e).Count() == 1);
            Assert.True(arc.Intersect(1e-4, seg_e).First().EqualsTol(1e-2, 3.53, 4.82, -1.93));
            Assert.True(arc.IntersectArc(1e-4, rad_tol, seg_e).Count() == 0);
        }
示例#16
0
        public void Arc3DTest_007()
        {
            var tol = 1e-7;

            var p1  = new Vector3D(20.17459383, 178.42487311, -56.31435851);
            var p2  = new Vector3D(1.7990927, 231.58612295, -18.13420814);
            var p3  = new Vector3D(262.37695212, 302.11773752, 132.19450446);
            var arc = new Arc3D(tol, p1, p2, p3);

            var cso  = new Vector3D("X = -153.32147396 Y = 128.44203407 Z = -156.2065643");
            var csv1 = new Line3D(cso, new Vector3D("X = 71.66072643 Y = 278.03911571 Z = -156.2065643"));
            var csv2 = new Line3D(cso, new Vector3D("X = -153.32147396 Y = 128.44203407 Z = 2.05865164"));

            Assert.True(arc.Intersect(1e-6, arc.CS.Move(arc.CS.BaseZ * 1000)).Count() == 0);

            var csplane = new CoordinateSystem3D(cso, csv1.V, csv2.V);
            var ipts    = arc.Intersect(tol, csplane).ToList();

            Assert.True(ipts.Count == 2);
            var ipLine = new Line3D(ipts[0], ipts[1]);

            Assert.True(ipts.Any(r => r.EqualsTol(tol, new Vector3D("X = 1.7990927 Y = 231.58612296 Z = -18.13420814"))));
            Assert.True(ipts.Any(r => r.EqualsTol(tol, new Vector3D("X = 169.80266871 Y = 343.29649219 Z = 134.36668758"))));
        }
示例#17
0
        public override void ExecuteCmd(string szContent, ref GenContext Context, ref ArrayList Output, ref Object Tag)
        {
            base.ExecuteCmd(szContent, ref Context, ref Output, ref Tag);
            if (!(Tag is SceneTree))
            {
                throw new Exception("LineCommand::ExecuteCmd:The last parameter must be a SceneTree instance");
            }
            SceneTree sct = (SceneTree)Tag;

            int iPos = -1;

            string szPar1  = GenContext.GetFirstParam(szContent, ref iPos, ','); //x1
            string szPar2  = GenContext.GetNextParam(szContent, ref iPos, ',');  //y1
            string szPar3  = GenContext.GetNextParam(szContent, ref iPos, ',');  //z1
            string szPar4  = GenContext.GetNextParam(szContent, ref iPos, ',');  //a
            string szPar5  = GenContext.GetNextParam(szContent, ref iPos, ',');  //b
            string szPar6  = GenContext.GetNextParam(szContent, ref iPos, ',');  //phi0
            string szPar7  = GenContext.GetNextParam(szContent, ref iPos, ',');  //phi1
            string szPar8  = GenContext.GetNextParam(szContent, ref iPos, ',');  //nLong
            string szPar9  = GenContext.GetNextParam(szContent, ref iPos, ',');  //color
            string szPar10 = GenContext.GetNextParam(szContent, ref iPos, ',');  //type obsolete (for compatibility)
            string szPar11 = GenContext.GetNextParam(szContent, ref iPos, ',');  //keyname

            if (GenContext.GetNextParam(szContent, ref iPos, ',') != "")
            {
                throw new Exception("ArcCommand:Invalid argument list.");
            }

            if (szPar8 == "")
            {
                szPar8 = "6";
            }
            if (((Convert.ToInt32(szPar8)) % 2) == 1)
            {
                throw new Exception("The amount of segment must be an 'even' value");
            }
            if (szPar9 == "")
            {
                szPar9 = "ffffff";
            }
            szPar10 = "0"; //type
            int iCount = sct.m_Object3DList.Count + 1;

            if (szPar11 == "")
            {
                szPar11 = "\"Arc" + iCount.ToString() + "\"";
            }
            Object3D ob      = sct.GetObject3D(szPar11);
            Arc3D    mayeArc = null;

            if (ob != null)
            {
                if (!(ob is Arc3D))
                {
                    throw new Exception("ArcCommand::ExecuteCmd:A 3DObject is already called like this");
                }
                sct.DeleteObject3D(ref ob);
            }
            float x1 = (float)Context.EvalFloat(szPar1);
            float y1 = (float)Context.EvalFloat(szPar2);
            float z1 = (float)Context.EvalFloat(szPar3);

            float rx   = (float)Context.EvalFloat(szPar4);
            float rz   = (float)Context.EvalFloat(szPar5);
            float phi0 = (float)Context.EvalFloat(szPar6);
            float phi1 = (float)Context.EvalFloat(szPar7);

            szPar11 = Context.EvalText(szPar11);

            int nLong = Convert.ToInt32(szPar8); // Multiply by 2 to get enough point for the primitives

            mayeArc = new Arc3D(new Vector3(x1, y1, z1), rx, rz, phi0, phi1, nLong, System.Drawing.Color.FromArgb(Int32.Parse(szPar9, System.Globalization.NumberStyles.HexNumber)), szPar11, false);
            Scene3D sc = (Scene3D)sct.m_MainSceneNode.m_Scene3DRef;

            sct.AddObject3D(sc.m_Keyname, mayeArc);
        }
示例#18
0
        public void Arc3DTest_001()
        {
            var o   = new Vector3D(4.4249, 1.0332, -3.7054);
            var cs_ = new CoordinateSystem3D(o,
                                             new Vector3D(-.1201, 4.4926, 1.4138),
                                             new Vector3D(-1.6282, 3.2952, 2.1837));

            // build cs for arc with same cad representation
            var csCAD = new CoordinateSystem3D(o, cs_.BaseZ, CoordinateSystem3DAutoEnum.AAA);

            var r     = 4.2753;
            var ang1  = 63.97731d.ToRad();
            var ange2 = 26.10878d.ToRad();
            var arc   = new Arc3D(1e-4, csCAD, r, ang1, ange2);
            var c     = new Circle3D(arc);

            var seg_i   = new Line3D(2.2826, 10.2516, -3.7469, 1.3767, -3.7709, 1.5019);
            var ip_circ = c.Intersect(1e-4, seg_i, segment_mode: false);
            var ip_arc  = arc.Intersect(1e-2, seg_i);

            // segment intersecting arc
            Assert.True(ip_circ.Count() == 1);
            Assert.True(ip_circ.First().EqualsTol(1e-4, ip_arc.First()));
            Assert.True(ip_circ.First().EqualsTol(1e-2, 1.83, 3.24, -1.12));

            // segment not intersecting arc
            var seg_i2 = seg_i.Scale(seg_i.From, .3);

            Assert.True(c.Intersect(1e-4, seg_i2, segment_mode: true).Count() == 0);
            Assert.True(arc.Intersect(1e-4, seg_i2, segment_mode: true).Count() == 0);

            // segment not intersecting, but line intersecting arc
            Assert.True(c.Intersect(1e-4, seg_i2, segment_mode: false).Count() == 1);
            Assert.True(c.Intersect(1e-4, seg_i2, segment_mode: false).First().EqualsTol(1e-4, ip_arc.First()));

            // segment intresecting circle, but not arc
            var seg_e = new Line3D(2.4523, 9.6971, -1.8004, 4.6142, -.0631, -2.0519);

            Assert.True(c.Intersect(1e-4, seg_e, segment_mode: false).Count() == 1);
            Assert.True(c.Intersect(1e-4, seg_e, segment_mode: false).First().EqualsTol(1e-2, 3.53, 4.82, -1.93));
            Assert.True(arc.Intersect(1e-4, seg_e).Count() == 0);

            // Geometry
            Assert.True(arc.GeomFrom.EqualsTol(1e-3, arc.From));
            Assert.True(arc.GeomTo.EqualsTol(1e-3, arc.To));
            var vertexes = arc.Vertexes.ToList();

            Assert.True(vertexes.Count == 2 &&
                        vertexes.Any(a => a.EqualsTol(1e-3, arc.From)) &&
                        vertexes.Any(a => a.EqualsTol(1e-3, arc.To)));

            // PtAngle and mid
            var midpoint = arc.MidPoint;

            Assert.True(arc.PtAtAngle(arc.AngleStart + arc.Angle / 2).EqualsTol(1e-3, midpoint));

            // segment
            Assert.True(arc.Segment.EqualsTol(1e-3, new Line3D(arc.From, arc.To)));

            // arc equals
            Assert.True(arc.EqualsTol(1e-3, new Arc3D(1e-3, arc.From, arc.MidPoint, arc.To)));
            Assert.True(arc.EqualsTol(1e-3, new Arc3D(1e-3, arc.CS, arc.Radius, arc.AngleStart, arc.AngleEnd)));
            Assert.False(arc.EqualsTol(1e-3, new Arc3D(1e-3, arc.CS, arc.Radius / 2, arc.AngleStart, arc.AngleEnd)));
            Assert.False(arc.EqualsTol(1e-3, new Arc3D(1e-3, arc.CS.Move(new Vector3D(1, 0, 0)),
                                                       arc.Radius, arc.AngleStart, arc.AngleEnd)));
            Assert.False(arc.EqualsTol(1e-3, new Arc3D(1e-3, arc.CS, arc.Radius, arc.AngleStart + 1, arc.AngleEnd + 1)));

            // arc bulge
            Assert.True(arc.Bulge(1e-3, arc.From, arc.To, arc.CS.BaseZ).EqualsTol(1e-3, Tan(arc.Angle / 4)));
            Assert.True(arc.Bulge(1e-3, arc.From, arc.To, -arc.CS.BaseZ).EqualsTol(1e-3, -Tan(arc.Angle / 4)));

            // arc contains
            Assert.False(arc.Contains(1e-3, new Vector3D(3.084, 3.965, -1.843), onlyPerimeter: false)); // out arc shape - in plane
            Assert.False(arc.Contains(1e-3, new Vector3D(2.821, 4.417, -2.795), onlyPerimeter: false)); // out of plane

            Assert.True(arc.Contains(1e-3, new Vector3D(5.446, 3.708, -3.677), onlyPerimeter: false));  // arc shape - in plane
            Assert.False(arc.Contains(1e-3, new Vector3D(5.142, 3.774, -4.713), onlyPerimeter: false)); // out of plane

            // read arc from dxf and use comparer
            {
                var doc = netDxf.DxfDocument.Load("_torefact/doc/Arc3DTest_001.dxf");

                var arc_from_dxf = doc.Arcs.First().ToArc3D(1e-3);
                var cmp          = new Arc3DEqualityComparer(1e-3);
                var q            = new[] {
                    arc_from_dxf,
                    arc,
                    new Arc3D(1e-3, arc.From, arc.MidPoint, arc.To),
                    new Arc3D(1e-3, arc.CS, arc.Radius, arc.AngleStart, arc.AngleEnd)
                };
                Assert.True(q.Distinct(cmp).Count() == 1);

                Assert.True(arc_from_dxf.EqualsTol(1e-3, ((netDxf.Entities.Arc)arc.DxfEntity).ToArc3D(1e-3)));
            }
        }
        /// <summary>
        /// Ritorna anteprima della lavorazione
        /// </summary>
        /// <returns></returns>
        protected override List <IEntity3D> GetFinalPreview()
        {
            try
            {
                var rslt = new List <IEntity3D>();

                if (PatternDrilling != null)
                {
                    var diameter = DiametroMetricoFinale;

                    if (diameter == 0)
                    {
                        diameter = 1;
                    }

                    var pntList = PatternDrilling.GetPointList();

                    foreach (var point2D in pntList)
                    {
                        var arc = new Arc3D {
                            Radius = diameter / 2, Center = new Point3D(point2D.X, point2D.Y, 0)
                        };

                        arc.Start = new Point3D(arc.Center);

                        arc.Start.X += arc.Radius;

                        arc.End = new Point3D(arc.Center);

                        arc.End.X += arc.Radius;

                        rslt.Add(arc);
                    }

                    foreach (var entity3D in rslt)
                    {
                        entity3D.PlotStyle = EnumPlotStyle.Element;
                    }
                }

                return(rslt);
            }
            catch (Exception)
            {
                throw new Exception("FresaturaFilettatura.GetPreview");
            }

            return(null);

            //var cerchio = new Arc2D
            //{
            //    Center = new Point2D(CentroX, CentroY),
            //    Radius = Raggio,
            //    ClockWise = false,
            //    Start = { X = CentroX + Raggio },
            //    End = { X = CentroX + Raggio },
            //};


            //cerchio.Start.Y = CentroY;
            //cerchio.End.Y = CentroY;


            //var profile2D = new Profile2D();

            //profile2D.AddEntity(cerchio);

            //cerchio.PlotStyle = EnumPlotStyle.Element;
            //return profile2D;


            //try
            //{
            //    if (Pattern != null)
            //    {
            //        var preview = Pattern.GetClosedProfile().Source;

            //        return Entity3DHelper.Get3DProfile(preview).ToList();
            //    }

            //}
            //catch (Exception ex)
            //{
            //}

            return(null);
        }
示例#20
0
        /// <summary>
        /// Stampa arco 3D
        /// L'elemento deve essere già definito , ( devono essere noti centro . start. end . raggio .clockwise
        /// </summary>
        /// <param name="arc3D"></param>
        private void PlotElement(Arc3D arc3D)
        {
            // ottengo dimensione massima scena
            // se pensi che prenda troppe risorse , modificare variabile solo quando si aggiunge scena
            //var sceneMaxWidth = view.GetCooAxisDim();

            var radius = arc3D.Radius;

            /*
             * Più questo rapporto è grande , piu il raggio può essere approsimato ( disegnato con meno segmenti)
             */
            var rapportoScenaArco = _sceneMaxWidth / radius * 2;

            // Se diametro cerchio coincide con ampiezza scenza , per disegnare la cfr usero il numero di segmenti max
            const int arcSegmentMaxNumber = 200;
            const int arcSegmentMinNumber = 20;

            // se il risultato non è soddisfacente provare con proporzione
            var segmentUsed = arcSegmentMaxNumber / rapportoScenaArco;

            if (segmentUsed < arcSegmentMinNumber)
            {
                segmentUsed = arcSegmentMinNumber;
            }

            //var l = new CubeMesh();
            var arcWire = new PolyLine();

            var center = arc3D.Center;

            var startAngle = GeometryHelper.GetPositiveAngle(arc3D.Start.X - center.X, arc3D.Start.Y - center.Y);

            var endAngle = GeometryHelper.GetPositiveAngle(arc3D.End.X - center.X, arc3D.End.Y - center.Y);

            /*
             * Piccolo hack per disegnare cerchio
             */
            {
            }
            var deltaZ = arc3D.End.Z - arc3D.Start.Z;

            var currentZ = arc3D.Start.Z;

            var incrementoAngolo = (Math.PI * 2) / segmentUsed;

            arcWire.AddPnt(new Point3D(arc3D.Start.X, arc3D.Start.Y, arc3D.Start.Z));

            //var deltaA = GeometryHelper.GetDeltaAngle(startAngle, endAngle, arc3D.ClockWise);



            /*
             * Se arco è clockwise , angolo finale è minore ,
             *
             * si parte da angolo iniziale e si diminuisce fino a angolo finale
             */
            if (arc3D.ClockWise)
            {
                /*
                 * Se il senso è antiorario l'angolo finale dovra essere maggiore
                 */

                if (startAngle < 0)
                {
                    startAngle += Math.PI * 2;
                    endAngle   += Math.PI * 2;
                }

                if (endAngle >= startAngle)
                {
                    endAngle -= 2 * Math.PI;
                }

                var deltaAngle = endAngle - startAngle;

                if (deltaAngle == 0)
                {
                    /* è un cerchio completo*/
                    endAngle  -= Math.PI * 2;
                    deltaAngle = endAngle - startAngle;
                }

                var numeroIncrementiAngolo = (int)Math.Ceiling(Math.Abs(deltaAngle) / incrementoAngolo);

                var incrementoZ = deltaZ / numeroIncrementiAngolo;

                // Se è clocwise angolo diminuisce
                for (var i = startAngle; i >= endAngle; i -= incrementoAngolo)
                {
                    currentZ += incrementoZ; // incremento contralle

                    var x = (Math.Cos(i) * radius) + center.X;
                    var y = (Math.Sin(i) * radius) + center.Y;

                    arcWire.AddPnt(new Point3D(x, y, currentZ));
                }
            }
            else // Arco antiorario
            {
                /*
                 * Se arco è ccw , angolo è maggiore ,
                 *
                 * si parte da angolo iniziale e si aumenta fino a angolo finale
                 *
                 */

                if (startAngle < 0)
                {
                    startAngle += Math.PI * 2;
                    endAngle   += Math.PI * 2;
                }

                /*
                 * Se arco antiorario angolo finale dovra essere maggiore
                 */

                if (endAngle < startAngle)
                {
                    endAngle += 2 * Math.PI;
                }

                var deltaAngle = endAngle - startAngle;


                if (deltaAngle == 0)
                {
                    /* è un cerchio completo*/
                    /* */

                    endAngle  += Math.PI * 2;
                    deltaAngle = endAngle - startAngle;
                }

                var numeroIncrementiAngolo = (int)Math.Ceiling(Math.Abs(deltaAngle) / incrementoAngolo);

                var incrementoZ = deltaZ / numeroIncrementiAngolo;

                for (var i = startAngle; i <= endAngle; i += incrementoAngolo)
                {
                    currentZ += incrementoZ;

                    var x = (Math.Cos(i) * radius) + center.X;
                    var y = (Math.Sin(i) * radius) + center.Y;

                    arcWire.AddPnt(new Point3D(x, y, currentZ));
                }
            }

            arcWire.AddPnt(new Point3D(arc3D.End.X, arc3D.End.Y, arc3D.End.Z));

            SetColor(arcWire, arc3D);

            AddWireElement(arcWire);
        }
示例#21
0
 /// <summary>
 /// create circle from given arc
 /// </summary>
 /// <param name="arc">arc used to build circle</param>
 public Circle3D(Arc3D arc) : base(arc.From, arc.MidPoint, arc.To)
 {
     Type = GeometryType.Circle3D;
 }