This is sort of an open ended question. I am trying to write a python script that rotates a plane to align with the ground. I have to use the plane itself instead of its origin point. I have accomplished one rotation in one direction so far using some trig stuff. But I think there has to be a better way to do this. Please let me know if you know of a solution other wise I'll just keep coding this one lol.


basically what I've done is flatten it out like you would if you where looking at the scene from one direction and then just worked with the triangles. I figure if I just work my way around it (Z and Y directions next) I can eventually get it flat.


1 Answer 1


I will able to piece together a much more elegant solution, once I understood how matrixes work a little better. I'm still a little confused by this code but It does what it needs to. https://www.youtube.com/watch?v=cWcAwfF6zgM

import bpy
from mathutils import Matrix, Vector

def scale_from_vector(v):
    mat = Matrix.Identity(4)
    for i in range(3):
        mat[i][i] = v[i]
    return mat    

o2 = bpy.data.objects['Cubeface002']
face  = o2.data.polygons[0] 

loc_dst, rot_dst, scale_dst = o2.matrix_world.decompose()

q = face.normal.rotation_difference((0, 0, 1))

o2.matrix_world = (
    Matrix.Translation(loc_dst) @ 
    q.to_matrix().to_4x4() @ 

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .