You can convert a vector in world space to an object’s space by multiplying the vector by the object’s orientation matrix and you can return back to world space multipling to local vector by the inverse of the object’s orientation matrix, the use of the mathutils Vector and Matrix classes help here, if you are on 2.5 you don’t need to worry about that though.

```
world_vector = local_vector * obj.worldOrientation
local_vector_again = world_vector * obj.worldOrietnation.copy().invert()
```

Angles between vectors can be found using the .angle() method of a Vector:

```
import math
angle = math.degrees(vector1.angle(vector2)) # the return type is in radians.
```

As for seeing if your object is aligned to the ground, something like this should be helpful:

```
import math
obj = ...
hit_normal = ... # in world space
angle = math.degrees(obj.worldOrietnation[2].angle(hit_normal))
if angle < acceptable_alignment_threshold: # such as 10, depends on how rough your ground is
print("object is aligned to ground")
```