Exemplo n.º 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);
            }
Exemplo n.º 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));
        }
Exemplo n.º 3
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;
            }
Exemplo n.º 4
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)));
        }
Exemplo n.º 5
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));
        }