Home | Trees | Indices | Help |
|
---|
|
1 # The Vision Egg: ThreeDeeMath 2 # 3 # Copyright (C) 2001-2003 Andrew Straw. 4 # Copyright (C) 2008 California Institute of Technology 5 # 6 # URL: <http://www.visionegg.org/> 7 # 8 # Distributed under the terms of the GNU Lesser General Public License 9 # (LGPL). See LICENSE.TXT that came with this file. 10 11 """ 12 Vertex and matrix operations - simulate OpenGL transforms. 13 14 """ 15 16 import math 17 import numpy 18 import numpy.oldnumeric as Numeric, numpy.oldnumeric.mlab as MLab 1921 """Convert vertex (or row-wise vertices) into homogeneous coordinates.""" 22 v = Numeric.array(v,typecode=Numeric.Float) # copy 23 if len(v.shape) == 1: 24 v = v[Numeric.NewAxis,:] # make a rank-2 array 25 if v.shape[1] == 3: 26 ws = Numeric.ones((v.shape[0],1),typecode=Numeric.Float) 27 v = Numeric.concatenate( (v,ws), axis=1 ) 28 return v2931 v = Numeric.asarray(v) 32 homog = make_homogeneous_coord_rows(v) 33 r = (homog/homog[:,3,Numeric.NewAxis])[:,:3] 34 if len(homog.shape) > len(v.shape): 35 r = Numeric.reshape(r,(3,)) 36 return r379840 if matrix is None: 41 self.matrix = MLab.eye(4,typecode=Numeric.Float) 42 else: 43 self.matrix = matrix44 4850 """Follows the right hand rule. 51 52 I visualize the right hand rule most easily as follows: 53 Naturally, using your right hand, wrap it around the axis of 54 rotation. Your fingers now point in the direction of rotation. 55 56 """ 57 angleRadians = angle_degrees / 180.0 * math.pi 58 u = self.__make_normalized_vert3(axis_x, axis_y, axis_z ) 59 u=-u #follow right hand rule 60 S = Numeric.zeros( (3,3), Numeric.Float ) 61 S[0,1] = -u[2] 62 S[0,2] = u[1] 63 S[1,0] = u[2] 64 S[1,2] = -u[0] 65 S[2,0] = -u[1] 66 S[2,1] = u[0] 67 U = Numeric.outerproduct(u,u) 68 R = U + math.cos(angleRadians)*(MLab.eye(3)-U) + math.sin(angleRadians)*S 69 R = Numeric.concatenate( (R,Numeric.zeros( (3,1), Numeric.Float)), axis=1) 70 R = Numeric.concatenate( (R,Numeric.zeros( (1,4), Numeric.Float)), axis=0) 71 R[3,3] = 1.0 72 self.matrix = numpy.dot(R,self.matrix)7375 T = MLab.eye(4,typecode=Numeric.Float) 76 T[3,0] = x 77 T[3,1] = y 78 T[3,2] = z 79 self.matrix = numpy.dot(T,self.matrix)8082 T = MLab.eye(4,typecode=Numeric.Float) 83 T[0,0] = x 84 T[1,1] = y 85 T[2,2] = z 86 self.matrix = numpy.dot(T,self.matrix)87 9092 v = Numeric.asarray(verts) 93 homog = make_homogeneous_coord_rows(v) 94 r = numpy.dot(homog,self.matrix) 95 if len(homog.shape) > len(v.shape): 96 r = Numeric.reshape(r,(4,)) 97 return r
Home | Trees | Indices | Help |
|
---|
Generated by Epydoc 3.0beta1 on Sat Jun 7 09:06:49 2008 | http://epydoc.sourceforge.net |