Changing axis rotation position
-
What I'm trying to do is a python tag that wobbles a cube inside a null - so in fact wobbles the null itself.
The rotation axis is centered on the cube's base. When it's at 0 degrees that's its axis rotation. However when it's below, the axis moves to one corner, and then the opposite happens for positive rotation.I would like to know how I can find out and offset that would allow me to rotate the black cube around the base center and then move it to the position it would have if it rotated around the corner. So basically the V vector on the drawing.
Unless there's a better way of changing the pivot point.
-
I do not fully understand the goal with the black center, why not always have two(left / right) red dots as pivot axis ?
Even though it might be clunky, have you tried to prototype your concept in X-Presso ? or even mechanical rigging. There was a good Maxon (by Noseman) tutorial on youtube a few weeks ago. -
-
Hello @SweepingMotion,
Thank you for reaching out to us. This topic is out of scope of support because it is just a math question. I will answer here once, but for follow-up questions you would have to rely on the community.
About your Question
Your question is ambiguous since you tell us what you want,
v
, but not what you know/have. Your image is also a bit confusing with the red and black rectangle being slightly offset on their local horizontal axis, but I assume that has been done to make the image more readable.I am going assume that you know the angle of your black rectangle in relation to the ground line and that you know the side length of the black rectangle.
This is then just a simple trigonometric identity. We have a point
O
which lies on a lineground
and the line segment/vectoropp
originating from it, which is half the side length of your rectangle long.ground
andopp
form a right triangle with an anglealpha
between them. We can therefore use the tangent relation to compute the adjacentadj
in this triangle whose length is identical tov
.v
is a vector with the lengthopp/tan(alpha)
and the orientationalpha
in relation to the ground line.Cheers,
Ferdinand -
@mogh @ferdinand
I'm building a python tag to handle these cards:
cards_script_v01.mp4
Works quite well when cards are flat. But I'd like to add some thickness. At the moment when crossing the vertical I move the top object to where the pivot should be and move the inside object in the opposite direction:
cards_script_v01-thickness.mp4
I was wondering though if there might be a better way of doing it.
The image in my original post was showing the situation - rotation around the central point at the base vs rotation around the corner of the base. Sorry if I didn't make myself clear.@ferdinand How would I construct this vector in c4d in python?
-
Hey @SweepingMotion,
I cannot help you more with the math, as such topics are out of scope of support. There is nothing special about how to construct the vector in our APIs.
You can either rotate a unit vector scaled to length, here assuming that up is the y-axis and alpha the z-axis.
v: c4d.Vector = c4d.Vector(0, length, 0) * c4d.utils.MatrixRotZ(alpha)
Or you can just scale the axis component of the global/local transform of your rectangle which is parallel with your
v
. I am again assuming that the local up is alongy
for your rectangle. This only works when the respective axis component is really parallel to v, but I assume that is the case here.# I operate here in global space, you could also do this locally. mg: c4d.Matrix = rectangle.GetMg() #The global transform of the rectangle. j: c4d.Vector = mg.v2.GetNormalized() # Its normalized v2/j/y component, its "y-axis" v: c4d.Vector = j * length # Or in one go v: c4d.Vector = rectangle.GetMg().v2.GetNormalized() * length
Cheers,
Ferdinand -
Thank you
-
My pleasure, and two answer you other question, yes, there are probably half a dozen ways to do this. The big alternative would be using transforms only and simply shifting to origin of operation to one of the corners of the cube before rotating it, and then move it. But these are all math questions, and SDK cannot teach users math.
But at least I would consider trigonometry in this case the easiest solution although I am usually not a big fan of excessive trigonometry usage, e.g., constructing rotation matrices by hand and so on.
Cheers,
Ferdinand -
@ferdinand I've played with your idea for a bit and then realized, that the point where the adj meets the ground is wrong, as it should be the point where a circle or f = opp with center in O meets the ground. Eventually I decided to just hack it a bit and change the position of the rotating object and the object inside to counter that move. Here's the result: