示例#1
0
    def test_Utils_Vector_OrthoBasis_GoodRandomRefVec(self):
        import numpy as np
        from opan.utils.vector import ortho_basis as ob
        from opan.utils.vector import vec_angle as ang

        nv = [8.5, -3.15, -2.1884]

        on1, on2 = ob(nv)

        self.assertAlmostEqual(np.dot(nv, on1), 0.0,
                delta=1e-10,
                msg="Normal vector not normal to first basis vector")

        self.assertAlmostEqual(np.dot(nv, on2), 0.0,
                delta=1e-10,
                msg="Normal vector not normal to second basis vector")

        self.assertAlmostEqual(np.dot(on1, on2), 0.0,
                delta=1e-10,
                msg="Basis vectors not normal")

        self.assertAlmostEqual(np.sum(np.power(on1, 2.)), 1.0,
                delta=1e-10,
                msg="First basis vector not normalized")

        self.assertAlmostEqual(np.sum(np.power(on2, 2.)), 1.0,
                delta=1e-10,
                msg="Second basis vector not normalized")

        self.assertAlmostEqual(ang(nv, np.cross(on1, on2)), 0.0,
                delta=1e-5,
                msg="Incorrect handedness of basis vectors")
示例#2
0
    def test_Utils_Vector_OrthoBasis_GoodDefinedRefVec(self):
        import numpy as np
        from opan.utils.vector import ortho_basis as ob
        from opan.utils.vector import vec_angle as ang
        from opan.utils.vector import rej

        nv = [2.5, 31.15, -25.1884]
        rv = [-12.15, 0.0034, 35.18]

        on1, on2 = ob(nv, rv)

        self.assertAlmostEqual(
            np.dot(nv, on1),
            0.0,
            delta=1e-10,
            msg="Normal vector not normal to first basis vector")

        self.assertAlmostEqual(
            np.dot(nv, on2),
            0.0,
            delta=1e-10,
            msg="Normal vector not normal to second basis vector")

        self.assertAlmostEqual(np.dot(on1, on2),
                               0.0,
                               delta=1e-10,
                               msg="Basis vectors not normal")

        self.assertAlmostEqual(np.sum(np.power(on1, 2.)),
                               1.0,
                               delta=1e-10,
                               msg="First basis vector not normalized")

        self.assertAlmostEqual(np.sum(np.power(on2, 2.)),
                               1.0,
                               delta=1e-10,
                               msg="Second basis vector not normalized")

        self.assertAlmostEqual(ang(nv, np.cross(on1, on2)),
                               0.0,
                               delta=1e-5,
                               msg="Incorrect handedness of basis vectors")

        self.assertAlmostEqual(
            ang(rej(rv, nv), on1),
            0.0,
            delta=1e-5,
            msg="First basis vector not aligned with reference")
示例#3
0
    def test_Utils_Vector_OrthoBasis_GoodRandomRefVec(self):
        import numpy as np
        from opan.utils.vector import ortho_basis as ob
        from opan.utils.vector import vec_angle as ang

        nv = [8.5, -3.15, -2.1884]

        on1, on2 = ob(nv)

        self.assertAlmostEqual(
            np.dot(nv, on1),
            0.0,
            delta=1e-10,
            msg="Normal vector not normal to first basis vector")

        self.assertAlmostEqual(
            np.dot(nv, on2),
            0.0,
            delta=1e-10,
            msg="Normal vector not normal to second basis vector")

        self.assertAlmostEqual(np.dot(on1, on2),
                               0.0,
                               delta=1e-10,
                               msg="Basis vectors not normal")

        self.assertAlmostEqual(np.sum(np.power(on1, 2.)),
                               1.0,
                               delta=1e-10,
                               msg="First basis vector not normalized")

        self.assertAlmostEqual(np.sum(np.power(on2, 2.)),
                               1.0,
                               delta=1e-10,
                               msg="Second basis vector not normalized")

        self.assertAlmostEqual(ang(nv, np.cross(on1, on2)),
                               0.0,
                               delta=1e-5,
                               msg="Incorrect handedness of basis vectors")
示例#4
0
    def test_Utils_Vector_ONCheck_SkewedVec(self):
        import numpy as np
        from scipy import linalg as spla
        from opan.utils.vector import orthonorm_check as onchk
        from opan.utils.vector import ortho_basis as ob

        vec = np.array([-6.277, 1.345, -23.8734])
        offvec = np.subtract(vec, np.array([-3, 5, -12]))
        offvec = offvec / spla.norm(offvec)

        on1, on2 = ob(vec)

        m = np.column_stack((offvec, on1, on2))

        c, nf, of = onchk(m, report=True)

        self.assertFalse(c)
        self.assertEqual(len(nf), 0)

        self.assertEqual(len(of), 2)
        self.assertEqual(of[0], (0,1))
        self.assertEqual(of[1], (0,2))
示例#5
0
    def test_Utils_Vector_ONCheck_Trivial2D(self):
        import numpy as np
        from scipy import linalg as spla
        from opan.utils.vector import orthonorm_check as onchk
        from opan.utils.vector import ortho_basis as ob

        vec = np.array([3.18, -2.25, 1.0005])
        on1, on2 = ob(vec)

        m = np.column_stack((vec / spla.norm(vec), on1, on2))

        c, nf, of = onchk(m)

        self.assertTrue(c)
        self.assertIsNone(nf)
        self.assertIsNone(of)

        c, nf, of = onchk(m, report=True)

        self.assertTrue(c)
        self.assertEqual(len(nf), 0)
        self.assertEqual(len(of), 0)
示例#6
0
    def test_Utils_Vector_ONCheck_SkewedVec(self):
        import numpy as np
        from scipy import linalg as spla
        from opan.utils.vector import orthonorm_check as onchk
        from opan.utils.vector import ortho_basis as ob

        vec = np.array([-6.277, 1.345, -23.8734])
        offvec = np.subtract(vec, np.array([-3, 5, -12]))
        offvec = offvec / spla.norm(offvec)

        on1, on2 = ob(vec)

        m = np.column_stack((offvec, on1, on2))

        c, nf, of = onchk(m, report=True)

        self.assertFalse(c)
        self.assertEqual(len(nf), 0)

        self.assertEqual(len(of), 2)
        self.assertEqual(of[0], (0, 1))
        self.assertEqual(of[1], (0, 2))
示例#7
0
    def test_Utils_Vector_ONCheck_Trivial2D(self):
        import numpy as np
        from scipy import linalg as spla
        from opan.utils.vector import orthonorm_check as onchk
        from opan.utils.vector import ortho_basis as ob

        vec = np.array([3.18, -2.25, 1.0005])
        on1, on2 = ob(vec)

        m = np.column_stack((vec / spla.norm(vec), on1, on2))

        c, nf, of = onchk(m)

        self.assertTrue(c)
        self.assertIsNone(nf)
        self.assertIsNone(of)

        c, nf, of = onchk(m, report=True)

        self.assertTrue(c)
        self.assertEqual(len(nf), 0)
        self.assertEqual(len(of), 0)
示例#8
0
    def test_Utils_Vector_OrthoBasis_GoodDefinedRefVec(self):
        import numpy as np
        from opan.utils.vector import ortho_basis as ob
        from opan.utils.vector import vec_angle as ang
        from opan.utils.vector import rej

        nv = [2.5, 31.15, -25.1884]
        rv = [-12.15, 0.0034, 35.18]

        on1, on2 = ob(nv, rv)

        self.assertAlmostEqual(np.dot(nv, on1), 0.0,
                delta=1e-10,
                msg="Normal vector not normal to first basis vector")

        self.assertAlmostEqual(np.dot(nv, on2), 0.0,
                delta=1e-10,
                msg="Normal vector not normal to second basis vector")

        self.assertAlmostEqual(np.dot(on1, on2), 0.0,
                delta=1e-10,
                msg="Basis vectors not normal")

        self.assertAlmostEqual(np.sum(np.power(on1, 2.)), 1.0,
                delta=1e-10,
                msg="First basis vector not normalized")

        self.assertAlmostEqual(np.sum(np.power(on2, 2.)), 1.0,
                delta=1e-10,
                msg="Second basis vector not normalized")

        self.assertAlmostEqual(ang(nv, np.cross(on1, on2)), 0.0,
                delta=1e-5,
                msg="Incorrect handedness of basis vectors")

        self.assertAlmostEqual(ang(rej(rv, nv), on1), 0.0,
                delta=1e-5,
                msg="First basis vector not aligned with reference")
示例#9
0
    def test_Utils_Vector_ONCheck_NonNormedVec(self):
        import numpy as np
        from opan.utils.vector import orthonorm_check as onchk
        from opan.utils.vector import ortho_basis as ob

        vec = np.array([-2.112, 2923.3, -0.2323])
        on1, on2 = ob(vec)

        m = np.column_stack((vec, on1, on2))

        c, nf, of = onchk(m)

        self.assertFalse(c)
        self.assertIsNone(nf)
        self.assertIsNone(of)

        c, nf, of = onchk(m, report=True)

        self.assertFalse(c)
        self.assertEqual(len(of), 0)

        self.assertEqual(len(nf), 1)
        self.assertEqual(nf[0], 0)
示例#10
0
    def test_Utils_Vector_ONCheck_NonNormedVec(self):
        import numpy as np
        from opan.utils.vector import orthonorm_check as onchk
        from opan.utils.vector import ortho_basis as ob

        vec = np.array([-2.112, 2923.3, -0.2323])
        on1, on2 = ob(vec)

        m = np.column_stack((vec, on1, on2))

        c, nf, of = onchk(m)

        self.assertFalse(c)
        self.assertIsNone(nf)
        self.assertIsNone(of)

        c, nf, of = onchk(m, report=True)

        self.assertFalse(c)
        self.assertEqual(len(of), 0)

        self.assertEqual(len(nf), 1)
        self.assertEqual(nf[0], 0)
示例#11
0
    def test_Utils_Vector_OrthoBasis_BadRefArrayLen(self):
        import numpy as np
        from opan.utils.vector import ortho_basis as ob

        with self.assertRaises(ValueError):
            ob(np.array(range(1,4)), np.array(range(6)))
示例#12
0
    def test_Utils_Vector_OrthoBasis_BadNormArrayShape(self):
        import numpy as np
        from opan.utils.vector import ortho_basis as ob

        with self.assertRaises(ValueError):
            ob(np.array(range(9)).reshape((3,3)))
示例#13
0
    def test_Utils_Vector_OrthoBasis_BadRefArrayLen(self):
        import numpy as np
        from opan.utils.vector import ortho_basis as ob

        with self.assertRaises(ValueError):
            ob(np.array(range(1, 4)), np.array(range(6)))
示例#14
0
    def test_Utils_Vector_OrthoBasis_BadNormArrayShape(self):
        import numpy as np
        from opan.utils.vector import ortho_basis as ob

        with self.assertRaises(ValueError):
            ob(np.array(range(9)).reshape((3, 3)))