Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rotating Trimesh mesh plane object

Tags:

python

trimesh

I'm starting to work with trimesh objects and i haven't been able to find good info on how to apply transformations to mesh objects (specifically,rotations).

I have a simple planar mesh object:

plane = trimesh.creation.box(extents=[20, 20, 0.01])

How can i rotate it -for example- over an axis?

like image 570
Ghost Avatar asked Dec 27 '25 21:12

Ghost


1 Answers

Take a look at this module and especially at this function.

The rotation_matrix requires the direction, angle and center of rotation (optional) as arguments to return the rotation matrix. Then, you can rotate your mesh by using the apply_transform method which requires the rotation_matrix as argument.

Here is the code:

import math
from trimesh import creation, transformations

plane = creation.box(extents=[20, 20, 0.01])

angle = math.pi / 4
direction = [1, 0, 0]
center = [0, 0, 0]

rot_matrix = transformations.rotation_matrix(angle, direction, center)

plane.apply_transform(rot_matrix)
like image 163
blunova Avatar answered Dec 30 '25 10:12

blunova