Center Axis with Python
-
Hi,
With python, I generate a ring in space that is far from the center (0,0,0)
The ring is in the plane formed by two vectors u and v.
The vector w is perpendicular to the ring.
After creating the ring, its center axis is at the position (0,0,0)
I would like to place the center axis at the center of the ring whose position I know.
In addition, I would like the axes of the center axis to correspond to the base (u,v,w) in which I created the ring. -
Hi @Kantronin,
I'm struggling to understand what exactly you're trying to achieve here. For your further postings please double check our Support Precedures, namely the How To Ask Questions section. Your question is also lacking the scope of question (taking into account you're posting in "General Talk"). Please note, that for the end-user questions we kindly ask you to proceed to our Support Center, where our colleauges can provide you with better support on given topic.
With that's said and as you've mentioned you're using python, I move your posting to the "Cinema 4D SDK" subforum and give you some hints.
I kind of induce that you want to align the global coordinate system with the local coordinate system of your object. However, the way you're saying it that you'd like to move the origin of your document into the origin of your object, confuses me a bit.
You can check the Workplane Modes to set your workplane properly (e.g. lock it to your object ring):
If what you're trying to do is to work with the transformation of your object, please refer to our Matrix Manual, which explains how transformations work for objects in cinema 4d. In this case you can either work with commands utilizing the transformation manipulation of the object, such as
"Reset Transform" if you'd like to move your object to the origin or "Freeze Transform", if you'd like to define the local coordinate system for the object (which is addressed as "relative" in our API). You might be also interested in "Center to ..." group of commands, which offer you a toolset on most common transfomation manipulation actions.
When you'd like to work with bare matrices, I suspect that what you're looking for is the transformation from the global origin into the object's local coordinate system, which would be defined as a global transformation matrix of the object c4d.BaseObject.GetMg():
originToObject: c4d.Matrix = op.GetMg()
or in the opposite direction is the inverse of such matrix:
objectToOrigin: c4d.Matrix = ~op.GetMg()
Cheers,
Ilia -
Let me explain.
My problem may be complicated to understand, but my final request is very simple.
In C4D, I've got into the habit of creating my 3D objects with splines, which allows me to create objects of any kind.
I do this with Python.
So to create a ring, I create 4 splines. Then, with these 4 splines, I create the ring.If my 4 splines are centered on the point (0,0,0) as shown in the image below, my ring lies on the XZ plane.
The axis center of the ring is also on the point (0,0,0). What's more, it's well oriented, as its Y axis corresponds to the Y axis of my ring.
Furthermore, the X axis of the axis center is aligned with the segments connecting the point (0,0,0) with the first points of my construction splines.
In this case, everything is perfect.
Figure 1However, if the center of my 4 splines is elsewhere and the orientation is arbitrary, as shown in the image below, this is where the problem arises.
After creating my ring, the axis center remains at the point (0,0,0) and its orientation is identical to the previous case.
Figure 2So I need to use Python to bring the axis center back to the center of my ring (translation).
Next, I need to rotate the axis center so that its Y axis is perpendicular to the plane of my ring.
Next, I need to rotate the axis center around its Y axis, so that its X axis is parallel to the segments connecting the center of the ring with the first points of my construction splines.In conclusion:
I need the following functions:- a function that allows the translation of the axis center, from a point A to a point B
- a function that allows the rotation of the axis center around its X axis
- a function that allows the rotation of the axis center around its Y axis
- a function that allows the rotation of the axis center around its Z axis
-
The following example illustrates my problem.
In this example, I translate and rotate the ring using C4D's interface.In figure 1, the ring is at point (0,0,0) with an angle of zero.
Figure 1In figure 2, using the Cinema 4D interface, I translate the ring with the vector <2,1,3> in centimeters.
Then I performed three successive rotations: 322° on the X axis, 30° on the Y axis and 343° on the Z axis.
Cinema 4D positioned the axis center of the ring correctly.
Figure 1But when I create my ring with 4 splines, at a point in space other than (0,0,0), the axis center always remains at the point (0,0,0) with an angle of zero.
I'd like the axis center to be at the center of my ring and at the same angle as in Cinema 4D. -
Hi @Kantronin,
Instead of creating multiple consequent postings please consolidate them in a single one. I've also noticed that you've added "programming" tag but haven't mentioned the language you're talking about (is it c++ or python?).
Regarding your questions. Transforming the axis of a PointObject effectively means transforming the point values. There're some helping commands that I've shown you in my previous message, but what they effectively do is just transforming the points. Please have a look into the operation_transfer_axis_s26.py example, which demonstrates how to perform axis translation.
As for the rotation part, I'd need to point you once again to our Matrix Manual, which actually contains the answer to your question. Namely, the chapter "Constructing and Combining Transforms" explains the usage of functions c4d.utils.MatrixRotX(), c4d.utils.MatrixRotY() and c4d.utils.MatrixRotZ(). I will not copy & paste the same code snippet from our manual, so please check it youself.
Combining these with the example above should do the trick for you, unless you don't have the initial transformation of your ring splines. If that's the case, then your task turns into a way more complex form of the optimization problem.
Please also note, that you can only do the object axis transformations on PointObject (and on PolygonObject since it's inherited from PointObject). This effectively means that if you're using the Osplinecircle instead of an ordinary Ospline, this wouldn't work, as it doesn't store any points inside. In this case you'd need to convert to Ospline. If that's not an option for you, you can check the Geometry Axis and Geometry Orientation scene nodes, as they allow you to transform the axis "on-the-fly", so this would work even with non-point objects.
Cheers,
Ilia