def test_gp_Quaternion(self):
        '''
        Test Interpolate method of qp_QuaternionSLerp.
        This method takes a by ref parameter q.
        '''
        vX = gp_Vec(12, 0, 0)
        vY = gp_Vec(0, 12, 0)

        q = gp_Quaternion()
        q1 = gp_Quaternion(vX, vX)
        q2 = gp_Quaternion(vX, vY)
        interp = gp_QuaternionSLerp(q1, q2)
        interp.Init(q1, q2)
        for i in range(10):
            i__ = i / 10.
            interp.Interpolate(i__, q)
            if i == 0:
                self.assertEqual(q.X(), 0.)
                self.assertEqual(q.Y(), 0.)
                self.assertEqual(q.Z(), 0.)
                self.assertEqual(q.W(), 1.)
            else:
                self.assertEqual(q.X(), 0.)
                self.assertEqual(q.Y(), 0.)
                self.assertGreater(q.Z(), 0.)
                self.assertLess(q.W(), 1.)
 def test_gp_Quaternion(self):
     '''
     Test Interpolate method of qp_QuaternionSLerp.
     This method takes a by ref parameter q.
     '''
     vX = gp_Vec(12, 0, 0)
     vY = gp_Vec(0, 12, 0)
     v45 = (gp_Vec(1, 1, 1).Normalized() * 12)
     q = gp_Quaternion()
     q1 = gp_Quaternion(vX, vX)
     q2 = gp_Quaternion(vX, vY)
     interp = gp_QuaternionSLerp(q1, q2)
     interp.Init(q1, q2)
     for i in range(10):
         i__ = i / 10.
         interp.Interpolate(i__, q)
         if i == 0:
             self.assertEqual(q.X(), 0.)
             self.assertEqual(q.Y(), 0.)
             self.assertEqual(q.Z(), 0.)
             self.assertEqual(q.W(), 1.)
         else:
             self.assertEqual(q.X(), 0.)
             self.assertEqual(q.Y(), 0.)
             assert q.Z() > 0.
             assert q.W() < 1.
Exemplo n.º 3
0
def interpolate(event=None):
    display.EraseAll()

    origin = gp_Vec()
    vX = gp_Vec(12, 0, 0)
    vY = gp_Vec(0, 12, 0)
    v45 = (gp_Vec(1, 1, 1).Normalized() * 12)

    q = gp_Quaternion()
    interp = gp_QuaternionSLerp(gp_Quaternion(vX, vX), gp_Quaternion(vX, vY))

    for i in frange(0, 1.0, 0.01):
        interp.Interpolate(i, q)
        # displace the white edges a little from the origin so not to obstruct the other edges
        v = gp_Vec(0, -24*i, 0)
        q_v_ = q * v45
        p = gp_Pnt((q_v_ + v).XYZ())
        v__as_pnt = gp_Pnt((origin + v).XYZ())
        e = make_edge(v__as_pnt, p)
        display.DisplayColoredShape(e, 'WHITE')
        msg = 'v45->q1*v45 @{0}'.format(i / 10.)
        display.DisplayMessage(p, msg)
    display.FitAll()