Solved Rotation for polygon

Hi,
I want to do a rotation for a polynone.
I know the coordinates of the points of the polygon, in the global coordinate system.
For this rotation, I know the axis of rotation, defined by a vector V, and the angle of rotation A with respect to this axis.

I manage to do this type of rotation, with matrices and with a change of Cartesian coordinate system, but I know that there is a much simpler method with C4D python functions

Hello @kantronin,

Thank you for reaching out to us. I am not quite sure how your last sentence is meant,

I manage to do this type of rotation, with matrices and with a change of Cartesian coordinate system, but I know that there is a much simpler method with C4D python functions

but you can define a rotation matrix from an axis of rotation v and an angle w with the function c4d.utils.RotAxisToMatrix(v, w). I.e., to transform vertices of an object, you would do something like this:

axis: c4d.Vector = c4d.Vector(1, 2, 3)
theta: float = c4d.utils.DegToRad(45)
transform: c4d.Matrix = c4d.utils.RotAxisToMatrix(axis, theta)

transformedPoints: list[c4d.Vector] = [transform * p for p in somePointObject.GetAllPoints()]

This transformation would however here happen in local object space, i.e., the space vertices/points are being expressed in. If you want to do the rotation in a space relative to the polygon, you will have to construct a frame for that polygon first, then convert the points out of local object space into your custom polygon space, carry out your rotation, and then convert the points back. I am just mentioning this because you talk about '[..] do[ing] a rotation for a polyon' which somewhat implies that you want to rotate around the origin of the polygon and some frame implied by the polygon.

Cheers,
Ferdinand

MAXON SDK Specialist
developers.maxon.net

Hello @kantronin,

Thank you for reaching out to us. I am not quite sure how your last sentence is meant,

I manage to do this type of rotation, with matrices and with a change of Cartesian coordinate system, but I know that there is a much simpler method with C4D python functions

but you can define a rotation matrix from an axis of rotation v and an angle w with the function c4d.utils.RotAxisToMatrix(v, w). I.e., to transform vertices of an object, you would do something like this:

axis: c4d.Vector = c4d.Vector(1, 2, 3)
theta: float = c4d.utils.DegToRad(45)
transform: c4d.Matrix = c4d.utils.RotAxisToMatrix(axis, theta)

transformedPoints: list[c4d.Vector] = [transform * p for p in somePointObject.GetAllPoints()]

This transformation would however here happen in local object space, i.e., the space vertices/points are being expressed in. If you want to do the rotation in a space relative to the polygon, you will have to construct a frame for that polygon first, then convert the points out of local object space into your custom polygon space, carry out your rotation, and then convert the points back. I am just mentioning this because you talk about '[..] do[ing] a rotation for a polyon' which somewhat implies that you want to rotate around the origin of the polygon and some frame implied by the polygon.

Cheers,
Ferdinand

MAXON SDK Specialist
developers.maxon.net

@ferdinand

Thanks, it works well

My first method was complex:

  • creation of a new orthogonal spatial system, with one of its axes is identical to the axis of rotation
  • compute the coordinates of the points of the object in this new spatial system, then rotate the object
  • calculation of the new coordinates in the initial orthogonal spatial system.