Forum Moderators: Lobo3433 Forum Coordinators: LuxXeon
Blender F.A.Q (Last Updated: 2024 Dec 01 9:08 pm)
Tough one, eh? :-) I've googled all over the place, and I've found some code, but it does not work. that is, the resulting quaternion, when used as obj.rotate_quaternion, does not result in properly rotated cylinder with ep1 = (0,0,0) and ep1 = (0,100,0)
def FindRotation(ep1, ep2):
vec = numpy.array(ep2) - numpy.array(ep1)
if not vec[0] and not vec[1]:
return (0,0,0)
print ("vec: %s"%str(vec))
Z = numpy.array((0,0,1))
kcostheta = numpy.dot(Z, vec)
k = Length(vec) # sqrt(Length(vec)^2 * Length(Z)^2) = Length(vec)
Q = Quaternion(numpy.cross(vec,Z), kcostheta+k)
Q.normalize()
print ("kcostheta: %f, k: %f, Q: %s"%(kcostheta, k, str(Q)))
return Q
Found a solution thanks to http://mcngraphics.com/thelab/blender/connect/
def FindRotation(ep1, ep2):
ep1 = numpy.array(ep1)
ep2 = numpy.array(ep2)
center = ep1 + 0.5 * (ep2 - ep1)
ep2new = ep2 - center
r = numpy.linalg.norm(ep2new) # radius of sphere
theta = math.acos(ep2new[2]/r)
phi = math.atan2( ep2new[1], ep2new[0])
return (0,theta, phi)
This site uses cookies to deliver the best experience. Our own cookies make user accounts and other features possible. Third-party cookies are used to display relevant ads and to analyze how Renderosity is used. By using our site, you acknowledge that you have read and understood our Terms of Service, including our Cookie Policy and our Privacy Policy.
I am stuck trying to make a cylinder given its endpoint locations and a radius. I need to compute the rotation for the following function call:
bpy.ops.mesh.primitive_cylinder_add(radius = radius, depth = depth, location = center, rotation = rotation)
How do I do this? For example, given endpoints (0,0,0) and (2,2,2), what value do I use for "rotation"? Thanks for any pointers.