Ejemplo n.º 1
0
            /// <summary>
            /// Note: tol must be Constant.NormalizedLengthTolerance
            /// if comparing normalized vectors
            /// rotation from-to will be multiplied for given angleFactor ( default 1.0 )
            /// </summary>
            public Vector3D RotateAs(double tol, Vector3D from, Vector3D to, double angleFactor = 1.0, double angleAddictional = 0)
            {
                var angle = from.AngleRad(tol, to) * angleFactor + angleAddictional;
                var N     = from.CrossProduct(to);

                return(this.RotateAboutAxis(N, angle));
            }
Ejemplo n.º 2
0
        public void AngleRadTest()
        {
            var v1      = new Vector3D(10, 0, 0);
            var v2      = new Vector3D(2, 5, 0);
            var angv1v2 = v1.AngleRad(1e-4, v2);
            var angv2v1 = v2.AngleRad(1e-4, v1);

            Assert.True(angv1v2.EqualsTol(rad_tol, angv2v1));
            Assert.True(angv1v2.EqualsTol(rad_tol, 68.2d.ToRad()));
        }
Ejemplo n.º 3
0
        public void Vector3DTest_0017()
        {
            var tol = 1e-8;

            var v1        = new Vector3D("X = 220.22063137 Y = 217.58532235 Z = 30.72201149");
            var v2        = new Vector3D("X = 41.2984487 Y = 335.41147265 Z = 65.72177141");
            var v1v2angle = v1.AngleRad(tol, v2);

            var dotp = v1.DotProduct(v2);

            // DotProduct implemented as sum or vectors components'product
            // test here with different approach: a b = |a| |b| cos(alfa)
            Assert.True(dotp.EqualsTol(tol, v1.Length * v2.Length * Cos(v1v2angle)));
        }
Ejemplo n.º 4
0
        public void Vector3DTest_0019()
        {
            var tol = 1e-8;

            var v1        = new Vector3D("X = 220.22063137 Y = 217.58532235 Z = 30.72201149");
            var v2        = new Vector3D("X = 41.2984487 Y = 335.41147265 Z = 65.72177141");
            var v1v2angle = v1.AngleRad(tol, v2);

            var cp = v1.CrossProduct(v2);

            // length of cross product is |a| |b| sin(alfa)
            Assert.True(cp.Length.EqualsTol(tol, v1.Length * v2.Length * Sin(v1v2angle)));

            // and is perpendicular to component vectors
            Assert.True(cp.IsPerpendicular(v1));
            Assert.True(cp.IsPerpendicular(v2));

            // test v1 x v2 = cp meet right hand rule
            var cpdir = new Vector3D("X = 15.98231081 Y = -52.81807432 Z = 259.51436001");

            Assert.True(cp.ConcordantColinear(tol, cpdir));
        }