0

I made a cuboid with the following code.

##defining to plot the cuboid
def 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)
   """
    ox, oy, oz = center
    l, w, h = size

   ###Added the fig in order to be able to plot it later
    ax = fig.gca(projection='3d') ##plot the project cuboid

    X=[ox-l/2,ox-l/2,ox-l/2,ox-l/2,ox+l/2,ox+l/2,ox+l/2,ox+l/2] ##corner points of the cuboid
    Y=[oy+w/2,oy-w/2,oy-w/2,oy+w/2,oy+w/2,oy-w/2,oy-w/2,oy+w/2]
    Z=[oz-h/2,oz-h/2,oz+h/2,oz+h/2,oz+h/2,oz+h/2,oz-h/2,oz-h/2]
    ax.scatter(X,Y,Z,c='g',marker='o')  #the plot before rotated

    X_new = ([]) #attaining new corner points after rotated
    Y_new = ([])
    Z_new = ([])

    for i in range(0,8):

        c=np.matrix([[X[i]], ##reading every corner points into matrix format
                    [Y[i]],
                    [Z[i]]])
        u=Rot_Mat*c ##rotating every corner point with the rotation matrix

        X_new = np.append(X_new, u.item(0)) ##appending the corner points with the neighbours
        Y_new = np.append(Y_new, u.item(1))
        Z_new = np.append(Z_new, u.item(2))

        print('\nvertex=\n',c)
        print('\nnew_vertex=\n',u)

        ###Doing a dot product between Rot_Mat and c as earlier but using np.dot as it is necessary with Numpy format, reshaping from(3,1) to (3)
        side[i,:] = np.dot(Rot_Mat, c).reshape(3)

    sides = [[side[0],side[1],side[2],side[3]], ##defining the 6 sides of cuboid
            [side[4],side[5],side[6],side[7]], 
            [side[0],side[1],side[4],side[5]], 
            [side[2],side[3],side[4],side[5]], 
            [side[1],side[2],side[5],side[6]],
            [side[4],side[7],side[0],side[3]]]

    ax.scatter(X_new,Y_new,Z_new,c='darkred',marker='o')  #the plot of corner points after rotated
    ax.scatter(ox,oy,oz,c='crimson',marker='o')  #the previous plot of center 

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

    ##labelling the axes
    ax.set_xlabel('X')
    ax.set_ylabel('Y')
    ax.set_zlabel('Z')
    ax.add_collection3d(Poly3DCollection(sides, facecolors='blue', linewidths=1, edgecolors='r', alpha=.25)) ###This draw the plane sides as requred 
    plt.gca().legend(('previous_center','previous_vertices','rotated_vertices','same_center'))




    ax.set_xlim([0,4.5])        
    ax.set_ylim([-.75,.75])
    ax.set_zlim([0,1])

I have few doubts in this. I want to plot y&z in one plot. That must be other plot to the given figure as sub plot. The frame must contain y&z axes of which x-axis should not be there. The background frame of the cuboid must be of different colour i.e. rather white black or yellow. So,can you give any suggestions or code hint in order to solve this.

0 Answers0