Example #1
0
        public void Line3DTest_006()
        {
            var l  = new Line3D(1, 2, 3, 4, 5, 6);
            var l2 = new Line3D(4, 5, 6, 7, 8, 9);

            Assert.True(l.CommonPoint(1e-1, l2).EqualsTol(1e-1, 4, 5, 6));
            var l3 = new Line3D(4.11, 5.11, 6.11, 7.11, 8.11, 9.11);

            // common point test only from,to
            Assert.True(l.CommonPoint(1e-1, l3) == null);
        }
Example #2
0
        public void BisectTest()
        {
            {
                var l1     = new Line3D(-.2653, 6.7488, 1.4359, 1.8986, 3.1188, 1.0844);
                var l2     = new Line3D(1.8986, 3.1188, 1.0844, 8.1864, 2.4120, 1.7818);
                var bisect = l1.Bisect(1e-4, l2);

                // bisect segment from start from the intersection point of two lines
                var ip = l1.CommonPoint(1e-4, l2);
                Assert.True(bisect.From.EqualsTol(1e-4, ip));

                var l1_from_ip = l1.EnsureFrom(1e-4, ip);
                var l2_from_ip = l2.EnsureFrom(1e-4, ip);

                // angle from bisect toward l1 equals angle from bisect toward l2
                var bisect_ang_l1 = bisect.V.AngleRad(1e-4, l1_from_ip.V);
                var bisect_ang_l2 = bisect.V.AngleRad(1e-4, l2_from_ip.V);
                Assert.True(bisect_ang_l1.EqualsTol(rad_tol, bisect_ang_l2));
            }

            {
                var l1 = new Line3D(0, 0, 0, 10, 0, 0);
                var l2 = new Line3D(0, 0, 0, -5, 0, 0);
                {
                    var bisect = l1.Bisect(1e-4, l2);
                    // two parallel lines not form a plane, then a fallback rotation axis must be given
                    Assert.True(bisect == null);
                }
                {
                    // rotate right-hand Z+
                    var bisect = l1.Bisect(1e-4, l2, Vector3D.ZAxis);
                    Assert.True(bisect.EqualsTol(1e-4, new Line3D(0, 0, 0, 0, 10, 0)));
                }
                {
                    // rotate right-hand Z-
                    var bisect = l1.Bisect(1e-4, l2, -Vector3D.ZAxis);
                    Assert.True(bisect.EqualsTol(1e-4, new Line3D(0, 0, 0, 0, -10, 0)));
                }
            }
        }