Как разместить кубоид на пиксельной рамке? - PullRequest
0 голосов
/ 14 июня 2019

Я создал трехмерное тело, как показано на рисунке 3D cuboid.Теперь я хочу разместить это тело на раме 4,5 метра х 1,5 метра от вида сверху.Рамка должна быть в формате пикселей, и каждый пиксель должен быть одинакового размера, но разного цвета.

###Added import
import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
from mpl_toolkits.mplot3d.art3d import Poly3DCollection, Line3DCollection

###Addded size and center in this format in order to manipulate them easily
size = [0.3, 0.4, 0.1]
center = [2.10737, -0.100085, 0.716869]

###This numpy vector will be used to store the position of the sides
side = np.zeros((8,3))

###Just re-ordered your matrix in some np.arrays
F = [[np.array([1., -0.001, -0.017])],
    [np.array([0., -0.999, 0.037])],
    [np.array([0.017, 0.037, 0.999])]]

def cuboid(center, size):
    ox, oy, oz = center
    l, w, h = size

    ###Added the fig in order to be able to plot it later
    fig = plt.figure()
    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]
    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]

    X_new = ([])
    Y_new = ([])
    Z_new = ([])

    for i in range(0,8):

        c=np.matrix([[X[i]],
                    [Y[i]],
                    [Z[i]]])
        u=F*c

        X_new = np.append(X_new, u.item(0))
        Y_new = np.append(Y_new, u.item(1))
        Z_new = np.append(Z_new, u.item(2))

        ###Doing a dot product between F and c like you did earlier but using np.dot as we're now working with Numpy format
        side[i,:] = np.dot(F, c)

    ###Storing the position of every points
    sides = [[side[0],side[1],side[2],side[3]],
            [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]]]


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



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

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

    ###This draw the plane sides as you wanted
    ax.add_collection3d(Poly3DCollection(sides, facecolors='blue', linewidths=1, edgecolors='r', alpha=.25))


cuboid(center, size)
###Mandatory to plot the cube
plt.show()

Итак, я ожидаю каких-либо предложений или изменений в коде, которые помогут мне пойти дальше.На самом деле я буду импортировать эти данные в мою камеру в виде изображений.Итак, мне нужна поддержка для этого.

...