0

See this picture. In this the cuboid has to rotate along the other axes that were marked in the picture but it stays in the same axis x,y,zThe image attached gives the code of the cuboid.

##defining to plot the cuboid
def plot_cuboid(center, size):
    """
   Create a data array for cuboid plotting.
   ============= ================================================
   Argument      Description
   ============= ================================================
   center        center of the cuboid, triple
   size          size of the cuboid, triple, (x_length,y_width,z_height)
   :type size: tuple, numpy.array, list
   :param size: size of the cuboid, triple, (x_length,y_width,z_height)
   :type center: tuple, numpy.array, list
   :param center: center of the cuboid, triple, (x,y,z)
   """

    # suppose axis direction: x: to left; y: to inside; z: to upper
    # get the (left, outside, bottom) point
    ox, oy, oz = center
    l, w, h = size

    ##defining the points
    x = np.linspace(ox-l/2,ox+l/2,num=10)
    y = np.linspace(oy-w/2,oy+w/2,num=10)
    z = np.linspace(oz-h/2,oz+h/2,num=10)

    ## defining surfaces and extrude them
    x1, z1 = np.meshgrid(x, z)
    y11 = np.ones_like(x1)*(oy-w/2)
    y12 = np.ones_like(x1)*(oy+w/2)
    x2, y2 = np.meshgrid(x, y)
    z21 = np.ones_like(x2)*(oz-h/2)
    z22 = np.ones_like(x2)*(oz+h/2)
    y3, z3 = np.meshgrid(y, z)
    x31 = np.ones_like(y3)*(ox-l/2)
    x32 = np.ones_like(y3)*(ox+l/2)

    ax = fig.gca(projection='3d') ##plot the project cuboid

    #plot outside surface
    ax.plot_surface(x1, y11, z1, color='red', rstride=1, cstride=1, alpha=0.6)
    #plot inside surface
    ax.plot_surface(x1, y12, z1, color='white', rstride=1, cstride=1, alpha=0.6)
    #plot bottom surface
    ax.plot_surface(x2, y2, z21, color='blue', rstride=1, cstride=1, alpha=0.6)
    #plot upper surface
    ax.plot_surface(x2, y2, z22, color='black', rstride=1, cstride=1, alpha=0.6)
    #plot left surface
    ax.plot_surface(x31, y3, z3, color='green', rstride=1, cstride=1, alpha=0.6)
    #plot right surface
    ax.plot_surface(x32, y3, z3, color='pink', rstride=1, cstride=1, alpha=0.6)

    ## Add title 
    plt.title('Plot_for_PSM', fontsize=20)

    ##labelling the axes
    ax.set_xlabel('X')
    ax.set_ylabel('Y')
    ax.set_zlabel('Z')

`

My question is that can we rotate the cuboid that was defined below with the euler angles in python?

center =(2.1,-0.1,0.757761) length=0.3, width=0.4, height=0.1 all in metres. as per the code in the attached image. Euler angles are 0,0,120 for example along x,y,z directions.

I have made some program to rotate a cuboid with the euler angles. But after attaining the euler angles how can I rotate the cuboid is my question. Can anyone suggest or attain the code for this problem?

Actually, I have quaternions which are converted into Euler angles and then want to rotate according to these Euler angles along their axes with right hand rule. You can view my code up to where I have done and also can suggest if anything wrong I have done.

In the code 'y' represents the angle with x-axis, 'p' represents the angle with y-axis, 'r' represents the angle with z-axis. the expected result is that the cuboid has to rotate along these euler angles(y,p,r) with respect to x,y,z axis.

Thanks in advance!

1 Answers1

0

First calculate the position vectors (the xyz coordinates) of the corners then use scipy.spatial.transform.Rotation on each corner.

DrBwts
  • 3,470
  • 6
  • 38
  • 62
  • Thank you. I will tray and confirm you for additional suggestion. One doubt is that the I have already extruded the cuboid from the centre of the body. Now, can I find the position vectors of the corners of this cuboid? – Pradeep Chakravarthi Nutakki Jun 06 '19 at 14:22
  • Is there any code that can be attached to the cuboid code that i have written before in this post that specifies the vertices of the corner of cuboid.? – Pradeep Chakravarthi Nutakki Jun 06 '19 at 15:16
  • you can calculate them from the centre point & the edge length. I leave that for you to work out... – DrBwts Jun 06 '19 at 20:01
  • even if i calculated the corner position then what is the use. I mean how can i proceed further – Pradeep Chakravarthi Nutakki Jun 07 '19 at 13:07
  • I have told you how to do it twice now. I'm not going to do your work for you that's not how this place works. Have you even tried what I suggested? I'm guessing not otherwise you would not be asking me to do it for you. – DrBwts Jun 07 '19 at 13:13
  • https://stackoverflow.com/questions/22175385/3d-matrix-perspective-transform/58650707#58650707 There is a good matrix transform here. – Cary H Nov 01 '19 at 11:01