 # H E L P !!! face normal to Euler ???

what’s the simplest method to translate facenormal to Euler to be used in a script that clones objects to face center ?
(I’ve used it for trees and perpendicular things, now I’d need it to rotate objects according to facenormal)

initial function is:

``````
def midpoint (face, mode):
mid = [0.0] * 3; qat = [0.0] * 3; mtx = [0, 1, 2]

for v in face.v:
for i in mtx: mid[i] += v.co[i]

for i in mtx:
mid[i] /= len(face.v); mid[i] = round (mid[i], 3)

if mode == 0: spawn(mid)

.... etc
``````

and it sends the location(s) to cloning function. so I’d like just to add calculation from face.no to Euler to send to cloning function.

nobody ??? theeth ???

A normal is a 3D vector, so it’s not quite enough for a full rotation. You can rotate around that vector using axis/angle rotation, one of the formats you can feed into Blender.Mathutils.Quaternion. I haven’t quite understood what the native quaternion format is, however. I gather what you want is to point a given axis (say, Y) along the given vector, though, and I haven’t figured that out correctly yet. The vector would essentially form one row of the rotation matrix, with the others being derived from it, but I’m not sure how.

nevermind got something cooking but it has some (minor) funny probs if some of normals gets close to zero. basically it is quite usable with smaller setups. I found jms’s mapmesh2lamp script and messed around with her lovely internals.

``````
def midpoint (face, mode):
mid = [0.0] * 3; qat = [0.0] * 3; nul =  * 3; mtx = [0, 1, 2]
nrm = sqrt(face.no ** 2 + face.no ** 2 + face.no ** 2)

for v in face.v:
for i in mtx: mid[i] += v.co[i]

for i in mtx:
mid[i] /= len(face.v); mid[i] = round (mid[i], 3)
face.no[i] /= nrm; face.no[i] = round (face.no[i], 3)

tht = acos(face.no)

if face.no != 0: thz = acos(face.no / sin(tht)) * face.no / abs(face.no)

# and the shitty line, should really make her behave ... :
else: thz = acos(face.no)

rot = [0, tht, thz]

if mode == 0: spawn (mid, rot)

elif mode == 1:
for v in face.v:
for i in mtx: qat[i] = (v[i] + mid[i]) / 2
spawn (qat, rot)
...etc

``````

BUT IF somebody has a perfect, elegant, full-blown working solution, PLEASE, be my guest You should create a 4x4 matrix using an arbitray axis (the face normal) and apply the matrix to each object.

thanks … any links to examples or tutorials maybe?