# Rotate Point around Axis

• On 05/06/2015 at 02:14, xxxxxxxx wrote:

I guess this is a simple and very common function. But I cant figure out how to do so in python. And I am stupid.

I want to rotate a Point selection around the modelling axis.

Question 1:
How do I calculate the rotation? I need a deffiniton which includes Point, RotationAxisMatrix,Rotation as parameter. I have tried to figure that out without luck till now.

Question 2: Is there a python function to get the Matrix of the Modelling-Axis in componentsmode?

• On 05/06/2015 at 08:15, xxxxxxxx wrote:

Hi,

This is isn't a so simple and common question .

Originally posted by xxxxxxxx

Question 1:
How do I calculate the rotation? I need a definiton which includes Point, RotationAxisMatrix, Rotation as parameter. I have tried to figure that out without luck till now.

First you should first have a good understanding of how matrices work in Cinema. See Matrix Fundamentals in the Python documentation.

Originally posted by xxxxxxxx

Question 2:
Is there a python function to get the Matrix of the Modelling-Axis in componentsmode?

There's no direct function for this. Here's some code:

``````def GetModelingAxis(op) :
tool = plugins.FindPlugin(c4d.ID_MODELING_AXIS, c4d.PLUGINTYPE_TOOL)

# Get modeling axis bounds
posx = tool[c4d.MDATA_AXIS_BOUNDS_X]
posy = tool[c4d.MDATA_AXIS_BOUNDS_Y]
posz = tool[c4d.MDATA_AXIS_BOUNDS_Z]

# Get center and bounding box of object
mp = op.GetMp()

# Initialize modeling axis with center of object
maxis = c4d.Matrix()
maxis.off = mp

# Change offset of modeling axis according to bounds

return maxis
``````

• On 08/06/2015 at 03:34, xxxxxxxx wrote:

Thanks a lot Yannick. I think this will help me.

• On 18/12/2015 at 16:17, xxxxxxxx wrote:

Hi Yanick, I have tried the Code you posted but it returns allways zero.
Is it possible that this function is broken?
Can you get it to work?

• On 19/12/2015 at 14:11, xxxxxxxx wrote:

Hey,

here are some lines to rotate selected points around the object axis. Hope it helps.

``````import c4d
#Welcome to the world of Python

def main() :
ref = op.GetDown()
clone = ref.GetClone()
ref_mg = ref.GetMg() #reference matrix
rot = op[c4d.ID_USERDATA,1] #vector

rot_mat = ref_mg*c4d.utils.MatrixRotX(rot.x)*c4d.utils.MatrixRotY(rot.y)*c4d.utils.MatrixRotZ(rot.z) #new rotation matrix about X,Y,Z

for i, sel in enumerate(ref.GetPointS().GetAll(ref.GetPointCount())) : #iterate all points
if sel: #check if point is selected
p = ref.GetPoint(i) #local position of point[i]
p_rot = p*~rot_mat #global position of point[i] out of the rotation matrix
new_p = ref_mg*p_rot #global position of point[i] into reference matrix to get the new local position
clone.SetPoint(i, new_p)
clone.Message(c4d.MSG_UPDATE)

ref.Touch()
return clone
``````