File: test_matToAxis.py

package info (click to toggle)
mgltools-mglutil 1.5.7~rc1%2Bcvs.20140424-1
  • links: PTS, VCS
  • area: non-free
  • in suites: jessie, jessie-kfreebsd
  • size: 7,292 kB
  • ctags: 3,325
  • sloc: python: 29,182; sh: 78; makefile: 17; csh: 4
file content (50 lines) | stat: -rw-r--r-- 1,488 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
## Automatically adapted for numpy.oldnumeric Jul 23, 2007 by 

from mglutil.regression import testplus
from FlexTree.FTMotions import FTMotion_RotationAboutAxis, FTMotion_Hinge
import numpy.oldnumeric as Numeric

def diff(res, expect):
    return res-expect < 1.0e-6  # close enough -> true


def rotateObject():
    from mglutil.math.rotax import rotax
    from math import sin, cos, pi, sqrt, fabs
    import numpy.oldnumeric as N
    import random

    degtorad = pi/180.
    point1 = [random.random()*8-4, random.random()*8-4.,random.random()*10-5]
    point2 = [random.random()*8-4, random.random()*8-4.,random.random()*10-5.]
    angle  = random.random()*360.
    transf = rotax(point1, point2, angle*degtorad, transpose=1)

    from mglutil.math.rotax import mat_to_axis_angle
    vector , pp, angle = mat_to_axis_angle(transf)

    from FlexTree.FTMotions import FTMotion_Hinge
    motion = FTMotion_Hinge(axis={'vector':vector,'point':pp})
    motion.configure(angle=angle)

    m1=Numeric.array(motion.getMatrix()).ravel()
    m2=transf.ravel()
    bSame = True
    for i in range(len(m1)):
        if fabs(m1[i]-m2[i]) > 1e-4:
            bSame = False
    assert bSame, True


def test_rotateObject():
    for i in range(10):
        rotateObject()
    

harness = testplus.TestHarness( __name__,
                              funs = testplus.testcollect( globals()),
                              )

if __name__ == '__main__':
    print harness
    sys.exit( len( harness))