ben Posted October 8, 2010 Share Posted October 8, 2010 I'm just starting with Python and as a learning case I'm wrting a small script to export points position in an xml. I'm using this script in a game engine to place geometry and it works fine. Now I would like to export orientation as well. To do that I need to convert point normal to rotation, and that's where I'm stuck... I'm not good at math so any hint (or a few lines) would be really apreciated. ben Quote Link to comment Share on other sites More sharing options...
SpencerL Posted October 8, 2010 Share Posted October 8, 2010 I recently had the same scenario come up which I had to convert a direction vector to degrees. I found this link to be useful as far as the math part is concerned. The "Axis Angle Result" section sums it up pretty well. http://www.euclideanspace.com/maths/algebra/vectors/angleBetween/index.htm Ive also attached a hip file which does this in a vop sop. convertDirToDegrees_001sl.hip Quote Link to comment Share on other sites More sharing options...
ben Posted October 8, 2010 Author Share Posted October 8, 2010 That's great, I won't have to spend my week end on it Thx Spencer ! Quote Link to comment Share on other sites More sharing options...
SpencerL Posted October 8, 2010 Share Posted October 8, 2010 That's great, I won't have to spend my week end on it Thx Spencer ! great! enjoy your weekend! Quote Link to comment Share on other sites More sharing options...
SpencerL Posted October 26, 2010 Share Posted October 26, 2010 great! enjoy your weekend! something I recently found to be wrong with my posted example is that I forgot to normalize the result of the cross vop. Be sure to stick a normalize VOP before the quaternion VOP or you may get results that are slightly off. Quote Link to comment Share on other sites More sharing options...
ben Posted October 26, 2010 Author Share Posted October 26, 2010 I notice, but since I round results before exporting to a game engine, I thought that was the reason (and not a big issue for me so I didn't investigate). Thanks Quote Link to comment Share on other sites More sharing options...
Ryan Posted October 27, 2010 Share Posted October 27, 2010 I use the quaternion VOP and the "rot" point attribute alot for stuff like this, instead of rotating normals. You can check out my attached sample. I don't know if it is helpful, but maybe it will become useful later on. Quote Link to comment Share on other sites More sharing options...
Ryan Posted October 27, 2010 Share Posted October 27, 2010 (edited) I use the quaternion VOP and the "rot" point attribute alot for stuff like this, instead of rotating normals. You can check out my attached sample. I don't know if it is helpful for what you want to do, but maybe it will become useful later on. rotationOfCopies.hip Edited October 27, 2010 by Ryan Quote Link to comment Share on other sites More sharing options...
jkunz07 Posted December 13, 2011 Share Posted December 13, 2011 Hey, I'm working on a project where I'm trying to do something similar. I've got some python code below that takes a line and computes a direction vector by comparing each point position by the next point position. Currently the code is placing a plane on each point and rotating it to face the direction vector, eventually I'm going to be instancing different geometry onto each point. The results I'm getting are very similar to the results of a sweep sop but some planes are "twisted" slightly. Below is an image, the wireframe planes are the result of the sweep sop and the shaded planes are the result of the code. I'm not sure if I can expect to get the same results as the sweep sop with only two vectors or if there's a problem with my math. import math geo = hou.pwd().geometry() # Input Geo normal_attrib = geo.addAttrib(hou.attribType.Point, "N", (0.0,0.0,0.0), True) # Create point normal attribute len_attrib = geo.addAttrib(hou.attribType.Point, "len", (0.0)) # Create point length attribute # Compute a direction vector for each point by subtracting the previous point's position from the current point position pos = hou.Vector3(0,0,0) for i in geo.points(): ptNormal = i.position() - pos i.setAttribValue(len_attrib, i.position().distanceTo(pos)) pos = i.position() i.setAttribValue(normal_attrib, ptNormal) # Fix incorrect values for for 1st point by assigning the values of the 2nd point geo.iterPoints()[0].setAttribValue(normal_attrib, geo.iterPoints()[1].attribValue("N")) geo.iterPoints()[0].setAttribValue(len_attrib, geo.iterPoints()[1].attribValue("len")) upVector = hou.Vector3(0,1,0) # Up Vector (+Y) for i in geo.points(): dirVector = hou.Vector3(i.attribValue("N")).normalized() # Normalized direction vector from point attribute "N" ang = hou.hmath.radToDeg(math.acos(upVector.dot(dirVector))) # Value in degrees of the Arc Cosine of Dot product of up and direction vectors rot = hou.hmath.buildRotateAboutAxis(upVector.cross(dirVector), ang) # Return a transformation matrix containing only a rotation, given an axis and a rotation amount if 1 == 1: plane = geo.createPolygon() point = geo.createPoint() point.setPosition(hou.Vector3(5.0,0.0,5.0)) plane.addVertex(point) point = geo.createPoint() point.setPosition(hou.Vector3(5.0,0.0,-5.0)) plane.addVertex(point) point = geo.createPoint() point.setPosition(hou.Vector3(-5.0,0.0,-5.0)) plane.addVertex(point) point = geo.createPoint() point.setPosition(hou.Vector3(-5.0,0.0,5.0)) plane.addVertex(point) geo.transformPrims( [plane], rot * hou.hmath.buildTranslate(i.position()) ) # Transform geo (Rotation Matrix * Translation Matrix) Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.