You need more than one vector to set an orientation since there are infinite orientations that can spin around the normal. You need at least 2 non-parallel vectors to create an orientation.
If you have a normal vector n and a tangent vector t, you can create an orthonormal basis by: x = n ^ t t = x ^ n Then you can pick which axis is which for your matrix: x.x x.y x.z 0 n.x n.y n.z 0 t.x t.y t.z 0 0 0 0 1 Chad On Tue, Aug 24, 2010 at 11:44 PM, Adam Miels <[email protected]> wrote: > Hi All. > > Not really a question specific to Python in Maya, but I am trying to > write this in python, and know that there are quite a few experienced > maya people on the list. > > I was wondering if there was possibly a better way to do this. > > I am querying a point on a surface, to get a normal vector, then > trying to use this vector to orient an objects rotation matrix so that > it points in the direction of surface. > I have written my own method to apply the transform as .setTransform > in pymel doesn't seem to work: > > def mySetMatrix(anObject, aMatrix): > > select(anObject) > > xform(m=(aMatrix.a00,aMatrix.a01,aMatrix.a02,aMatrix.a03, \ > > aMatrix.a10,aMatrix.a11,aMatrix.a12,aMatrix.a13, \ > > aMatrix.a20,aMatrix.a21,aMatrix.a22,aMatrix.a23, \ > > aMatrix.a30,aMatrix.a31,aMatrix.a32,aMatrix.a33)) > > I query the point on the surface with: > > normalVector = aMesh.getClosestNormal(aPoint, 'world')[0] > > and then use the X,Y,Z values of this vector to calculate the > following matrices: > > rotate on x axis: > where X = atan2(Y,Z) > > 1 0 0 0 > > 0 cosX -sinX 0 > > 0 sinX cosX 0 > > 0 0 0 1 > > > rotate on y axis: > where Y = atan2(X,Z) > > cosY 0 sinY 0 > > 0 1 0 0 > > -sinY 0 cosX 0 > > 0 0 0 1 > > > rotate on z axis: > where Z = atan2(Y,X) > > cosZ -sinZ 0 0 > > sinZ cosZ 0 0 > > 0 0 1 0 > > 0 0 0 1 > > and then assigning the resulting matrix (original Matrx) X (X Matrix) > X (Y Matrix) X (Z Matrix) to the original object. > > Although this approach seems to make sense to me on paper, when I > implement it, I get matrices that end up scaling the object instead of > only affecting its rotations, and they point in the wrong directions. > > I was wondering if anyone could point me in the right direction with > this one (literally :P ) ? > > Regards, > > Adam Miels. > > -- > http://groups.google.com/group/python_inside_maya -- http://groups.google.com/group/python_inside_maya
