Finding a matrix from one vector and another preferred up vector

Hello,
I’m having trouble getting some vector maths to work. I’m not sure what I’m doing wrong below…

I have a normalized Y vector which I want to maintain (ay), a preferred Z vector (0,0,1) and I want to find a rotation matrix.

My strategy is…



az=mathutils.Vector((0,0,1))
ax=ay.cross(az) #should give me a vector perpendicular to y and the up vector
az=ax.cross(ay) #should give me a new up vector which is 90 degrees to both x and y
m=mathutils.Matrix((ax,ay,az))


Where am I going wrong here?
Thanks!

ok, i just realised that there’s nothing wrong with this bit of code at all, the bug was elsewhere in my script.
Seems that in particle systems Particle.prev_location does not return the last location!