示例#1
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));
        }
 /// <summary>
 /// verify is this cs is equals to otherByLayer ( same origin, x, y, z base vectors )
 /// </summary>
 /// <param name="tol">calc tolerance ( for origin check )</param>
 /// <param name="other">cs to check equality against</param>
 /// <returns>true if this cs equals the given on, false otherwise</returns>
 /// <remarks>
 /// [unit test](/test/Vector3D/Vector3DTest_0001.cs)
 /// </remarks>
 public bool Equals(double tol, CoordinateSystem3D other)
 {
     return(Origin.EqualsTol(tol, other.Origin) &&
            BaseX.EqualsTol(tol, other.BaseX) &&
            BaseY.EqualsTol(tol, other.BaseY) &&
            BaseZ.EqualsTol(tol, other.BaseZ));
 }
示例#3
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);
            }
示例#4
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")));
        }
示例#5
0
            public bool IsParallelTo(double tol, CoordinateSystem3D cs)
            {
                var from_ = this.From.ToUCS(cs);
                var to_   = this.To.ToUCS(cs);

                return(from_.Z.EqualsTol(tol, to_.Z));
            }
示例#6
0
        public static IEnumerable <EntityObject> Explode(this Insert ins)
        {
            var insPt = ins.Position;

            var N      = ins.Normal;
            var ocs    = new CoordinateSystem3D(insPt, N).Rotate(N, ins.Rotation.ToRad());
            var origin = Vector3D.Zero.ToWCS(ocs);

            foreach (var ent in ins.Block.Entities)
            {
                // TODO scale
                // pts = pts.Select(w => w.ScaleAbout(Vector3D.Zero, ins.Scale.ToVector3D()));


                // pts = pts.Select(w => w.ToWCS(ocs));

                switch (ent.Type)
                {
                case EntityType.Circle:
                {
                    var c = (Circle)ent.CoordTransform((x) => x.ToWCS(ocs), origin);
                    c.Center = (c.Center + insPt);
                    yield return(c);
                }
                break;
                }
            }
        }
示例#7
0
 public Arc3D(CoordinateSystem3D cs, double r, double angleRadStart, double angleRadEnd) :
     base(GeometryType.Arc3D)
 {
     AngleStartRad = angleRadStart;
     AngleEndRad   = angleRadEnd;
     CS            = cs;
     Radius        = r;
 }
示例#8
0
 /// <summary>
 /// construct 3d arc
 /// </summary>
 /// <param name="cs">coordinate system with origin at arc center, XY plane of cs contains the arc, angle is 0 at cs x-axis and increase right-hand around cs z-axis</param>
 /// <param name="r">arc radius</param>
 /// <param name="angleRadStart">arc angle start (rad). is not required that start angle less than end. It will normalized 0-2pi</param>
 /// <param name="angleRadEnd">arc angle end (rad). is not require that end angle great than start. It will normalized 0-2pi</param>
 /// <returns>3d arc</returns>
 public Arc3D(double tol_len, CoordinateSystem3D cs, double r, double angleRadStart, double angleRadEnd) :
     base(GeometryType.Arc3D)
 {
     tol_rad    = tol_len.RadTol(r);
     AngleStart = angleRadStart.NormalizeAngle2PI(tol_rad);
     AngleEnd   = angleRadEnd.NormalizeAngle2PI(tol_rad);
     CS         = cs;
     Radius     = r;
 }
示例#9
0
        public void ToWCSTest()
        {
            var v_ = new Vector3D(.8791, -.4619, -2.6742);
            var cs = new CoordinateSystem3D(
                new Vector3D(1.8129, 1.8060, .2726),  // origin
                new Vector3D(1.8404, 2.0375, 1.3964), // v1
                new Vector3D(2.8872, .2899, 1.3186)); // v2
            var v = v_.ToWCS(cs);

            Assert.True(v.EqualsTol(1e-4, 1, 2, 3));
        }
示例#10
0
        /// <summary>
        /// enumerate as Vector3D given dxf lwpolyline vertexes
        /// </summary>
        public static IEnumerable <Vector3D> Vector3DCoords(this LwPolyline lwp)
        {
            var res = new List <Vector3D>();
            var N   = lwp.Normal;
            var ocs = new CoordinateSystem3D(Vector3D.Zero, N);

            foreach (var v in lwp.Vertexes)
            {
                yield return(MathHelper.Transform(
                                 new Vector3(v.Position.X, v.Position.Y, lwp.Elevation), lwp.Normal, CoordinateSystem.Object, CoordinateSystem.World));
            }
        }
示例#11
0
        public void Project1Test()
        {
            var cs = new CoordinateSystem3D(
                new Vector3D(6.1776, -6.3366, -5.7131),  // o
                new Vector3D(-2.8849, -7.6108, -1.8691), // v1
                new Vector3D(-11.7294, 5.4484, 6.7873)); // v2

            var v  = new Vector3D(1, 2, 3);
            var vp = v.Project(cs);

            Assert.True(vp.EqualsTol(1e-4, -.0151, 3.0158, .4304));
        }
示例#12
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;
            }
示例#13
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);
        }
示例#14
0
        void Coordinate3DSystemTest()
        {
            var p = new Vector3D(53.0147, 34.5182, 20.1);

            var o  = new Vector3D(15.3106, 22.97, 0);
            var v1 = new Vector3D(10.3859, 3.3294, 30);
            var v2 = new Vector3D(2.3515, 14.101, 0);

            var cs = new CoordinateSystem3D(o, v1, v2);

            var u = p.ToUCS(cs);

            Assert.True(u.EqualsTol(1e-4, 32.3623, 12.6875, -27.3984));
            Assert.True(u.ToWCS(cs).EqualsTol(1e-4, p));
        }
示例#15
0
        public void CoordinateSystem3DTest_003()
        {
            var cs1cad = new CoordinateSystem3D(new Vector3D(-1, 77, .75),
                                                new Vector3D(0, 0, 1),
                                                new Vector3D(.619, -.785, 0),
                                                new Vector3D(.785, .619, 0));

            var cs2cad = new CoordinateSystem3D(new Vector3D(-20.74, 55.485, 0),
                                                new Vector3D(0, 0, 1),
                                                new Vector3D(.619, -.785, 0),
                                                new Vector3D(.785, .619, 0));

            var delta = new Vector3D(-19.74, -21.515, -0.75);

            Assert.True(cs1cad.Move(delta).Equals(1e-3, cs2cad));
        }
示例#16
0
        public void CoordinateSystem3DTest_001()
        {
            var cs1cad = new CoordinateSystem3D(new Vector3D(-1, 77, .75),
                                                new Vector3D(0, 0, 1),
                                                new Vector3D(.619, -.785, 0),
                                                new Vector3D(.785, .619, 0));

            var rotationAxis = new Line3D(new Vector3D(.111, .652, 0), Vector3D.ZAxis, Line3DConstructMode.PointAndVector);

            var cs2    = cs1cad.Rotate(rotationAxis, 74.1566195.ToRad());
            var cs2cad = new CoordinateSystem3D(new Vector3D(-73.639, 20.427, .75),
                                                new Vector3D(0, 0, 1),
                                                new Vector3D(.924, .381, 0),
                                                new Vector3D(-.381, .924, 0));

            Assert.True(cs2.Equals(1e-3, cs2cad));
        }
示例#17
0
            /// <summary>
            /// find ips of intersect this arc to the given cs plane;
            /// return empty set if arc cs plane parallel to other given cs
            /// </summary>
            /// <param name="tol">len tolerance</param>
            /// <param name="cs">cs xy plane</param>
            /// <param name="only_perimeter">if false it will check in the arc area too, otherwise only on arc perimeter</param>
            /// <returns>sample</returns>
            /// <remarks>
            /// [unit test](/test/Arc3D/Arc3DTest_0001.cs)
            /// ![](/test/Arc3D/Arc3DTest_0001.png)
            /// </remarks>
            public IEnumerable <Vector3D> Intersect(double tol, CoordinateSystem3D cs,
                                                    bool only_perimeter = true)
            {
                if (this.CS.IsParallelTo(tol, cs))
                {
                    yield break;
                }

                var iLine = this.CS.Intersect(tol, cs);

                foreach (var x in this.Intersect(tol, iLine,
                                                 only_perimeter: only_perimeter,
                                                 segment_mode: false,
                                                 circle_mode: false))
                {
                    yield return(x);
                }
            }
示例#18
0
            public static (CoordinateSystem3D CS, double Radius) CircleBy3Points(Vector3D p1, Vector3D p2, Vector3D p3)
            {
                // https://en.wikipedia.org/wiki/Circumscribed_circle
                // Cartesian coordinates from cross- and dot-products

                var d = ((p1 - p2).CrossProduct(p2 - p3)).Length;

                var Radius = ((p1 - p2).Length * (p2 - p3).Length * (p3 - p1).Length) / (2 * d);

                var alpha = Pow((p2 - p3).Length, 2) * (p1 - p2).DotProduct(p1 - p3) / (2 * Pow(d, 2));
                var beta  = Pow((p1 - p3).Length, 2) * (p2 - p1).DotProduct(p2 - p3) / (2 * Pow(d, 2));
                var gamma = Pow((p1 - p2).Length, 2) * (p3 - p1).DotProduct(p3 - p2) / (2 * Pow(d, 2));

                var c = alpha * p1 + beta * p2 + gamma * p3;

                var CS = new CoordinateSystem3D(c, p1 - c, p2 - c);

                return(CS, Radius);
            }
示例#19
0
        public void CoordinateSystem3DTest_004()
        {
            var cs1cad = new CoordinateSystem3D(new Vector3D(-1, 77, .75),
                                                new Vector3D(0, 0, 1),
                                                new Vector3D(.619, -.785, 0),
                                                new Vector3D(.785, .619, 0));

            var cs2cad = new CoordinateSystem3D(new Vector3D(-1, 77, .75),
                                                new Vector3D(-0.649, .409, .642),
                                                new Vector3D(-.108, -.884, .454),
                                                new Vector3D(.753, .225, .618));

            var vaxis = new Vector3D(-.311, -1.15, -.75);

            Assert.True(cs1cad.Rotate(vaxis, 60d.ToRad()).Equals(1e-3, cs2cad));

            var pt = new Vector3D(-1.379, 76.762, 1.298);

            Assert.True(cs2cad.Contains(1e-3, pt) && !cs1cad.Contains(1e-3, pt));
        }
示例#20
0
            /// <summary>
            /// returns null if this line is parallel to the cs xy plane,
            /// the intersection point otherwise
            /// </summary>
            public Vector3D Intersect(double tol, CoordinateSystem3D cs)
            {
                if (IsParallelTo(tol, cs))
                {
                    return(null);
                }

                // O = plane.Origin    Vx = plane.CS.BaseX    Vy = plane.CS.BaseY
                //
                // plane : O + alpha * Vx + beta * Vy
                // line  : From + gamma * V
                //
                // => m:{ alpha * Vx + beta * Vy - gamma * V } * s = n:{ From - O }

                var m = Matrix3D.FromVectorsAsColumns(cs.BaseX, cs.BaseY, -V);
                var n = From - cs.Origin;
                var s = m.Solve(n);

                return(From + s.Z * V);
            }
示例#21
0
        public void CoordinateSystem3DTest_005()
        {
            var cs1o = new Vector3D("X = -2.67223215 Y = -94.22126913 Z = -293.08306335");
            var cs1x = new Line3D(cs1o, new Vector3D("X = -221.37919777 Y = 144.86810067 Z = -168.96320246"));
            var cs1y = new Line3D(cs1o, new Vector3D("X = 192.45964896 Y = 5.43267925 Z = -141.20969062"));
            var cs1  = new CoordinateSystem3D(cs1o, cs1x.V, cs1y.V);

            var cs2o = new Vector3D("X = -187.42845697 Y = 128.44203407 Z = 25.92565607");
            var cs2x = new Line3D(cs2o, new Vector3D("X = -9.40307509 Y = 246.81618785 Z = 25.92565607"));
            var cs2y = new Line3D(cs2o, new Vector3D("X = -187.42845697 Y = 128.44203407 Z = 224.4413331"));
            var cs2  = new CoordinateSystem3D(cs2o, cs2x.V, cs2y.V);

            var i12Line = cs1.Intersect(1e-4, cs2);
            var i21Line = cs2.Intersect(1e-4, cs1);

            Assert.True(i12Line.LineContainsPoint(1e-4, i21Line.From));
            Assert.True(i12Line.LineContainsPoint(1e-4, i21Line.To));
            Assert.True(i12Line.LineContainsPoint(1e-4, new Vector3D("X = -187.42845697 Y = 128.44203407 Z = -170.87092273")));
            Assert.True(i12Line.LineContainsPoint(1e-4, new Vector3D("X = 29.37373838 Y = 272.59999706 Z = 25.92565607")));
        }
示例#22
0
            /// <summary>
            /// build 3d circle that tangent to lines t1,t2 and that intersects point p
            /// note: point p must contained in one of t1,t2
            /// circle will be inside region t1.V toward t2.V
            /// they are 4 circles
            /// </summary>
            public static IEnumerable <Circle3D> CirclesTan12P(double tol_len, Line3D t1, Line3D t2, Vector3D p)
            {
                foreach (var da in new double[] { 0, PI / 2 })
                {
                    var ip    = t1.Intersect(tol_len, t2);
                    var angle = t1.V.AngleRad(tol_len, t2.V);
                    var t3    = new Line3D(ip, t1.V.RotateAs(tol_len, t1.V, t2.V, .5, da), Line3DConstructMode.PointAndVector);

                    Line3D lp  = null;
                    Line3D lNp = null;
                    if (t1.LineContainsPoint(tol_len, p))
                    {
                        lp = t1; lNp = t2;
                    }
                    else if (t2.LineContainsPoint(tol_len, p))
                    {
                        lp = t2; lNp = t1;
                    }
                    else
                    {
                        throw new Exception($"circle 2 tan 1 point : pt must contained in one of given tan");
                    }

                    var lpp = new Line3D(p, lp.V.RotateAboutAxis(t1.V.CrossProduct(t2.V), PI / 2), Line3DConstructMode.PointAndVector);
                    var c   = lpp.Intersect(tol_len, t3);

                    var Radius = p.Distance(c);
                    var CS     = new CoordinateSystem3D(c, lpp.V, t2.V);

                    yield return(new Circle3D(tol_len, CS, Radius));

                    // mirrored addictional circle

                    var mc = c.Mirror(new Line3D(p, p.Project(lNp) - p, Line3DConstructMode.PointAndVector));

                    yield return(new Circle3D(tol_len, new CoordinateSystem3D(mc, lpp.V, t2.V), Radius));
                }
            }
示例#23
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);
        }
示例#24
0
        public static BBox3D BBox(this EntityObject eo)
        {
            switch (eo.Type)
            {
            // TODO consider text width
            case EntityType.Text:
            // TODO consider text width
            case EntityType.MText:
            case EntityType.Line:
            case EntityType.Point:
            case EntityType.Insert:
                return(eo.Points().BBox());

            case EntityType.Arc:
            {
                var arc = (eo as Arc).ToArc3D();
                return(new BBox3D(new[] { arc.From, arc.To, arc.MidPoint }));
            }

            case EntityType.Circle: return(((Circle)eo).ToPolyline(4).BBox());

            case EntityType.LightWeightPolyline:
            {
                var lwpoly = (LwPolyline)eo;

                var N   = lwpoly.Normal;
                var ocs = new CoordinateSystem3D(N * lwpoly.Elevation, N);

                return(new BBox3D(eo.Points().Select(k => k.ToWCS(ocs))));
            }


            case EntityType.Hatch: return(new BBox3D());

            default:
                throw new NotImplementedException($"bbox not implemented for dxf entity type [{eo.Type.ToString()}]");
            }
        }
示例#25
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"))));
        }
示例#26
0
            /// <summary>
            /// return intersect line between two cs xy planes
            /// </summary>
            /// <param name="tol_len">len tolernace</param>
            /// <param name="other">other cs</param>
            /// <returns>null if cs parallel to the given other</returns>
            public Line3D Intersect(double tol_len, CoordinateSystem3D other)
            {
                if (this.IsParallelTo(tol_len, other))
                {
                    return(null);
                }

                var l1 = new Line3D(other.Origin, other.BaseX, Line3DConstructMode.PointAndVector);
                var l2 = new Line3D(other.Origin, other.BaseY, Line3DConstructMode.PointAndVector);

                var i1 = l1.Intersect(tol_len, this);
                var i2 = l2.Intersect(tol_len, this);

                if (i1 == null)
                {
                    i1 = i2 + l1.V;
                }
                else if (i2 == null)
                {
                    i2 = i1 + l2.V;
                }

                return(new Line3D(i1, i2));
            }
示例#27
0
        public void IntersectTest()
        {
            {
                var l  = new Line3D(0, 0, 0, 10, 0, 0);
                var l2 = new Line3D(5, 1e-1, 0, 5, 1e-1, 10); // vertical line dst=1e-1

                // default intersection behavior : midpoint
                var ip = l.Intersect(1e-1, l2);
                Assert.True(ip.EqualsTol(1e-2, l.Intersect(1e-1, l2, LineIntersectBehavior.MidPoint)));
                Assert.True(ip.EqualsTol(1e-2, 5, 1e-1 / 2, 0));

                ip = l.Intersect(1e-1, l2, LineIntersectBehavior.PointOnThis);
                Assert.True(ip.EqualsTol(1e-2, 5, 0, 0));

                ip = l.Intersect(1e-1, l2, LineIntersectBehavior.PointOnOther);
                Assert.True(ip.EqualsTol(1e-2, 5, 1e-1, 0));

                Assert.True(l.Intersect(5e-2, l2) == null);
            }

            {
                var l = new Line3D(0, 0, 0, 10, 20, 30);

                // cs around l=cs.z
                var cs = new CoordinateSystem3D(l.From, l.V, CoordinateSystem3DAutoEnum.AAA);

                // build a per line offsetted
                var lperp_off = new Line3D(l.MidPoint, cs.BaseX, Line3DConstructMode.PointAndVector)
                                .Move(cs.BaseY * 2e-1);

                var ip = l.Intersect(2e-1, lperp_off);
                Assert.True(ip.EqualsTol(1e-4, 4.9641, 9.9283, 15.0598));

                Assert.True(l.Intersect(1e-1, lperp_off) == null);
            }
        }
示例#28
0
 public Plane3D(CoordinateSystem3D cs)
 {
     CS = cs;
 }
示例#29
0
 public Vector3D ToWCS(CoordinateSystem3D cs)
 {
     return(cs.ToWCS(this));
 }
示例#30
0
 /// <summary>
 /// wcs coord of projected coord to the given cs
 /// </summary>
 /// <param name="v">wcs point</param>
 /// <param name="cs">cs to project</param>
 /// <param name="evalCSOrigin">if true cs origin will subtracted before transform, then readded to obtain wcs point</param>
 public static Vector3D Project(this Vector3D v, CoordinateSystem3D cs, bool evalCSOrigin = true)
 {
     return(v.ToUCS(cs, evalCSOrigin).Set(OrdIdx.Z, 0).ToWCS(cs, evalCSOrigin));
 }