使用Python从凸壳中着色固体表面?

时间:2018-06-13 14:32:14

标签: python colors surface shading

基于Python的问题,关于从一个顶点平滑地着色实体 到另一个为每个顶点分配RGB值。 我想用预定义的RGB颜色值对实体表面进行着色。 需要将RGB值分配给顶点位置。 期望从一个RGB值/顶点到另一个RGB值/顶点的平滑着色(插值)。 这是我目前的代码。谢谢。

# Imports/Libraries required.
from mpl_toolkits.mplot3d import Axes3D 
import matplotlib.pyplot as plt
import numpy as np
from mpl_toolkits.mplot3d.art3d import Poly3DCollection
from scipy.spatial import ConvexHull

# Define RGB colors at the vertices of the solid construct.
rgb = [[1.0, 1.0, 1.0],
   [0, 0.625, 0.89],
   [0.9, 0.06, 0.5],
   [0.92, 0.94, 0.85],
   [0.27, 0.11, 0.0],
   [0.18, 0.21, 0.53],
   [0.0, 0.6, 0.3],
   [0.89, 0.13, 0.15],
   [0.02, 0.12, 0.16],
   [0.18, 0.07, 0.098],
   [0.15, 0.16, 0.09]]
rgb = np.asarray(rgb)

# Define locations, xyz, of the vertices
xyz = [[0, 0, 100],
   [-38, -50, 58]
   [ 77, -2,  51],
   [ -5, 10, 94],
   [ 17, 41, 16 ],
   [18,-47, 26],
   [-71, 27, 53],
   [ 71, 51, 50],
   [-7, -10, 10],
   [15, 2.5, 10],
   [-4, 11, 16]]
xyz = np.asarray(xyz)

# Construct convex hull
primshull = ConvexHull(xyz) 

# Get vertices
vertices = [xyz[s] for s in primshull.simplices]

# Get triangles 
triangles = Poly3DCollection(vertices, edgecolor='k', alpha = 0.05)

# HOW TO COLOR the triangles/solid with the RGB values 
# at the vertices with smooth shaded interpolation between???
# so that I have smooth colors from vertice to vertice??
face_color = 'red'
triangles.set_facecolor(face_color)

fig1 = plt.figure(1)
ax = fig1.gca(projection='3d')  
ax.scatter(xyz[:,0],xyz[:,1],xyz[:,2], marker='o', s=5, alpha=1.0)
ax.add_collection3d(triangles)
plt.show()

0 个答案:

没有答案