3D Transformation Using Cube
3D Transformation Using Cube
# Translation function
def translate(vertices, tx, ty, tz):
translation_matrix = np.array([tx, ty, tz])
return vertices + translation_matrix
# Scaling function
def scale(vertices, sx, sy, sz):
scaling_matrix = np.array([
[sx, 0, 0],
[0, sy, 0],
[0, 0, sz]
])
return np.dot(vertices, scaling_matrix)
# Plotting function
def plot_cube(vertices, title):
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
faces = create_faces(vertices)
face_collection = Poly3DCollection(faces, alpha=0.25, linewidths=1, edgecolors=
face_collection.set_facecolor('cyan')
ax.add_collection3d(face_collection)
# Set labels
ax.set_xlabel('X')
ax.set_ylabel('Y')
ax.set_zlabel('Z')
plt.show()
In [ ]: