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
    • Categories
      • Overview
      • News & Information
      • Cinema 4D SDK Support
      • Cineware SDK Support
      • ZBrush 4D SDK Support
      • Bugs
      • General Talk
    • Unread
    • Recent
    • Tags
    • Users
    • Login

    How to calculate a rectangle corners position depending on her rotation

    Cinema 4D SDK
    c++ python
    3
    6
    1.0k
    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.
    • mfersaouiM
      mfersaoui
      last edited by mfersaoui

      Hi,

      I'm searching how to calculate a rectangle corners position depending on the rectangle rotation.
      below a simple example to illustrate what I want to do:

      # Rectangle size
      width = 200
      height = 100
      
      # Rectangle Coordinate
      rec_pos = Vector(0,0,0)
      rec_rot = Vector(0,0,0)
      
      # Calculate corners position when rectangle rotation = Vector(0,0,0)
      x_pos = width/2
      y_pos = height/2
      
      top_left_corner = Vector(rec_pos.x - x_pos, rec_pos.y + y_pos, rec_pos.z)
      top_right_corner = Vector(rec_pos.x + x_pos, rec_pos.y + y_pos, rec_pos.z)
      bottom_left_corner = Vector(rec_pos.x - x_pos, rec_pos.y - y_pos, rec_pos.z)
      bottom_right_corner = Vector(rec_pos.x + x_pos, rec_pos.y - y_pos, rec_pos.z)
      
      # Calculate corners position when rectangle rotation != Vector(0,0,0)
      # example
      rec_pos = Vector(0,0,0)
      rec_rot = Vector(90, 30, 0)
      
      top_left_corner =  ?
      top_right_corner =  ?
      bottom_left_corner = ?
      bottom_right_corner =  ?
      
      

      Thanks

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

        Hi,

        you will need a rotation matrix for that. There is c4d.utils.HPBToMatrix() which lets you construct a rotation matrix from a rotation vector, the input however is expected in radians and not in degrees. The rotated point is then p_rot = HPBToMatrix(angles) * p.

        Cheers
        zipit

        MAXON SDK Specialist
        developers.maxon.net

        mfersaouiM 1 Reply Last reply Reply Quote 0
        • r_giganteR
          r_gigante
          last edited by

          Hi @mfersaoui thanks for reaching out us and thanks @zipit for the given answer.

          On top of zipit's answer I recommend to check that the values first are set in radians and second that the proper rotation order set is selected otherwise you can easily end up with unexpected results.

          Cheers, R

          1 Reply Last reply Reply Quote 0
          • mfersaouiM
            mfersaoui @ferdinand
            last edited by

            @zipit
            Hi, Thanks @zipit and @r_gigante for your answers.

            I tried with HPBToMatrix but that works only if rectangle has as position Vector(0,0,0), but when the rectangle position change this doesn't work. Or I misused the HPBToMatrix function.

            Here is .c4d scene example: HPBToMatrix.c4d
            in my example the rectangle is replaced by a light object

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

              Hi,

              you will need to set the offset of the matrix returned by the function to the offset of your rectangle or translate your points manually into the desired frame of reference.

              Cheers,
              zipit

              MAXON SDK Specialist
              developers.maxon.net

              mfersaouiM 1 Reply Last reply Reply Quote 0
              • mfersaouiM
                mfersaoui @ferdinand
                last edited by mfersaoui

                @zipit
                Hi, Thank you so much.

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