How do we obtain the angle between global coordinates of an element and normal vector

Good morning everyone,

I’m interesting in constructing the rotation matrix in the global coordinates. So I’d need the three rotation angles between the normal of the element and the three axis, x, y and z.

Using

n = ufl.FacetNormal(final_mesh)
x = ufl.SpatialCoordinate(final_mesh)

x_x = ufl.as_vector([x[0]])
x_y = ufl.as_vector([x[1]])
x_z = ufl.as_vector([x[2]])
theta = inner(x_x, n)
phi = inner(x_y, n)
psi = inner(x_z, n)

seems a bit naive …
As well as

x_x = ufl.as_vector([1, 0, 0])
x_y = ufl.as_vector([0, 1, 0])
x_z = ufl.as_vector([0, 0, 1])
theta = inner(x_x, n)
phi = inner(x_y, n)
psi = inner(x_z, n)

Do you have any hint ?