Maxon Developers Maxon Developers
    • Documentation
      • Cinema 4D Python API
      • Cinema 4D C++ API
      • Cineware API
      • ZBrush GoZ API
      • Code Examples on Github
    • Forum
    • Downloads
    • Support
      • Support Procedures
      • Registered Developer Program
      • Plugin IDs
      • Contact Us
    • Unread
    • Recent
    • Tags
    • Users
    • Login

    Changing axis rotation position

    General Talk
    python 2024
    3
    8
    1.7k
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • S
      SweepingMotion
      last edited by

      What I'm trying to do is a python tag that wobbles a cube inside a null - so in fact wobbles the null itself. vector-01.png
      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.

      ferdinandF 1 Reply Last reply Reply Quote 0
      • M
        mogh
        last edited by

        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.

        S 1 Reply Last reply Reply Quote 0
        • ferdinandF ferdinand moved this topic from Cinema 4D SDK on
        • ferdinandF
          ferdinand @SweepingMotion
          last edited by ferdinand

          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.

          58fd4f93-3a0e-4b65-b97c-37115fdf25c5-image.png

          This is then just a simple trigonometric identity. We have a point O which lies on a line ground and the line segment/vector opp originating from it, which is half the side length of your rectangle long. ground and opp form a right triangle with an angle alpha between them. We can therefore use the tangent relation to compute the adjacent adj in this triangle whose length is identical to v.

          v is a vector with the length opp/tan(alpha) and the orientation alpha in relation to the ground line.

          Cheers,
          Ferdinand

          MAXON SDK Specialist
          developers.maxon.net

          1 Reply Last reply Reply Quote 1
          • S
            SweepingMotion @mogh
            last edited by SweepingMotion

            @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?

            ferdinandF 1 Reply Last reply Reply Quote 0
            • ferdinandF
              ferdinand @SweepingMotion
              last edited by ferdinand

              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 along y 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

              MAXON SDK Specialist
              developers.maxon.net

              1 Reply Last reply Reply Quote 0
              • S
                SweepingMotion
                last edited by

                Thank you

                1 Reply Last reply Reply Quote 0
                • ferdinandF
                  ferdinand
                  last edited by ferdinand

                  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

                  MAXON SDK Specialist
                  developers.maxon.net

                  S 1 Reply Last reply Reply Quote 0
                  • S
                    SweepingMotion @ferdinand
                    last edited by

                    @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:

                    1 Reply Last reply Reply Quote 1
                    • First post
                      Last post