Rotate Vector Around Axis

I’ve seen plenty of tutorials for how to rotate an object around a custom axis, but I still can’t figure out how to do what I want.
I’m making a plant growing plugin (yes, another one), and what I’m trying to do is this: I have the global rotation of a parent branch. I want to determine the direction of the child branches as follows:

  • Rotate the parent vector n degrees towards the (z?) axis
  • Rotate the resulting vector around the parent vectors by [index * 137.5078 degrees]

How would I do this? I want to do this without making each branch an object, so I will be operating directly with the mathutils.Vector type.

Thanks!

I think you should use the quaternion…or euler

this is some code from api
https://www.blender.org/api/blender_python_api_current/mathutils.html?highlight=vector#mathutils.Vector

<b>import</b> <b>mathutils</b><b>import</b> <b>math</b>

<i># create a new euler with default axis rotation order</i>
eul = mathutils.Euler((0.0, math.radians(45.0), 0.0), 'XYZ')

<i># rotate the euler</i>
eul.rotate_axis('Z', math.radians(10.0))

<i># you can access its components by attribute or index</i>
print("Euler X", eul.x)
print("Euler Y", eul[1])
print("Euler Z", eul[-1])

<i># components of an existing euler can be set</i>
eul[:] = 1.0, 2.0, 3.0

<i># components of an existing euler can use slice notation to get a tuple</i>
print("Values: <i>%f</i>, <i>%f</i>, <i>%f</i>" % eul[:])

<i># the order can be set at any time too</i>
eul.order = 'ZYX'

<i># eulers can be used to rotate vectors</i>
vec = mathutils.Vector((0.0, 0.0, 1.0))
vec.rotate(eul)

<i># often its useful to convert the euler into a matrix so it can be used as</i>
<i># transformations with more flexibility</i>
mat_rot = eul.to_matrix()
mat_loc = mathutils.Matrix.Translation((2.0, 3.0, 4.0)) mat = mat_loc * mat_rot.to_4x4()

some ref:

http://inside.mines.edu/fs_home/gmurray/ArbitraryAxisRotation/

Thanks! I recently asked my computer science teacher, and quaternions seem like an easier route to go, though. I’m going to see what I can find with those.

Quaternions are most definitely harder to implement than Euler rotations.