Example #1
0
    def test_decompose(self):

        #normal vector
        self.v.normalize()
        #change d to something thats not parallel to v
        self.d.y = 1

        #expected parallel vector
        respara = Vector2D()
        respara.x = respara.y = 1.5

        #expected perpendicullar vector
        resperp = Vector2D()
        resperp.x = 0.5
        resperp.y = -0.5

        para, perp = Vector2D.decompose(self.d, self.v)

        self.assertAlmostEqual(para, respara)
        self.assertAlmostEqual(perp, resperp)
Example #2
0
 def test_distance(self):
     dist = Vector2D.distance(self.v, self.d)
     self.assertAlmostEqual(dist, 4.242640687)
Example #3
0
 def test_dot(self):
     self.assertEqual(Vector2D.dot(self.v, self.d), 20)
Example #4
0
 def test_as_normalized(self):
     z = Vector2D.asNormalized(self.v)
     self.assertAlmostEqual(z.magnitude(), 1.0)