Python scipy Convexhull симплексов против часовой стрелки - PullRequest
0 голосов
/ 26 мая 2020

Я хотел бы сгенерировать выпуклый корпус (из пакета scipy) и преобразовать его в me sh (для библиотеки просмотра). Когда я рисую его, некоторые грани не отображаются, и мне сказали, что все треугольники должны быть повернуты «против часовой стрелки» (CCW).
Но я не уверен, что делать, чтобы определить, является ли треугольник CCW или нет. Вот пример моих треугольников с hull.simplices из from scipy.spatial import ConvexHull

from scipy.spatial import ConvexHull
import nglview as nv


positions = np.array([[-13.82,  -4.85,  -5.35],
       [-18.57,  -3.98,  -8.9 ],
       [-20.85,  -1.21,  -0.69],
       [-15.18,  -2.32,  -1.91],
       [-12.11,  -4.47,   3.19],
       [ -6.61,   1.38,   5.28],
       [ -6.21,  -1.93,   9.51],
       [ -5.71,  -6.8 ,   6.78],
       [ -2.9 ,  -8.38,  11.55],
       [ -0.16, -16.03,   7.74],
       [  0.62, -13.47,   2.77],
       [  2.4 , -17.9 ,   0.25],
       [  6.69, -14.21,   0.1 ],
       [  8.33, -16.39,  -4.85],
       [ 12.35, -19.19,  -2.26],
       [ 16.  , -15.71,  -1.86],
       [ 18.01, -20.21,  -5.52],
       [ 13.72, -22.44,  -4.69],
       [  9.71, -20.86,  -8.23],
       [  9.41, -23.33,  -2.74],
       [  4.42, -20.72,  -2.17],
       [  8.09, -19.95,   2.4 ],
       [  3.33, -20.03,   5.48],
       [  6.16, -15.07,   5.67],
       [  3.74, -13.49,  10.45],
       [  1.63, -10.56,   5.72],
       [  1.64,  -6.88,   9.77],
       [ -1.53,  -4.24,   5.73],
       [ -0.7 ,  -0.99,  10.26],
       [  0.4 ,   3.44,   8.87],
       [  3.69,   0.44,   6.13],
       [  3.09,  -4.49,   3.26],
       [  5.82,  -5.23,   8.51],
       [  7.75,  -9.34,   5.06],
       [  7.96, -11.64,  10.5 ],
       [ 13.28, -12.62,   9.12],
       [ 11.24, -17.73,   8.57],
       [ 16.36, -17.71,   7.16],
       [ 18.18, -13.96,   9.69],
       [ 14.98, -14.02,  14.77],
       [ 18.15,  -9.65,  12.19],
       [ 15.29,  -6.05,  11.44],
       [ 10.05,  -7.01,  10.19],
       [ 11.29,  -6.82,   4.94],
       [  8.56,  -1.71,   6.44],
       [  6.79,  -3.36,   1.29],
       [  6.29,   2.52,   1.06],
       [  0.96,   0.15,   0.18],
       [  2.53,   5.42,  -0.7 ],
       [  6.57,   3.8 ,  -3.48],
       [  4.43,  -1.17,  -3.4 ],
       [  2.36,  -1.12,  -8.55],
       [ -1.53,  -4.11,  -5.15],
       [  0.1 ,  -6.45, -10.39],
       [ -5.18,  -8.14,  -8.1 ],
       [ -4.03, -13.22, -10.33],
       [ -5.88, -11.36, -15.2 ],
       [ -7.5 , -15.98, -15.05],
       [ -4.07, -17.56, -11.49],
       [ -8.93, -16.88,  -7.9 ],
       [ -5.86, -17.56,  -4.41],
       [ -2.3 , -15.18,  -7.73],
       [ -1.84, -10.14,  -5.36],
       [  2.74,  -9.46,  -8.78],
       [  3.98,  -6.64,  -3.85],
       [  5.39,  -3.58,  -8.86],
       [  9.13,  -2.91,  -4.32],
       [ 11.49,   1.5 ,  -5.4 ],
       [ 14.19,  -0.39,  -9.19],
       [ 12.29,  -4.45,  -6.24],
       [  9.04,  -7.71,  -9.53],
       [  7.5 ,  -8.82,  -4.03],
       [  6.26, -13.74,  -6.2 ],
       [  2.26, -11.88,  -2.33],
       [  0.54, -17.05,  -3.28],
       [ -4.42, -15.37,  -0.86],
       [ -3.99, -19.22,   2.88],
       [ -8.69, -19.33,   1.76],
       [-11.48, -17.97,  -2.44],
       [-12.46, -15.89,   2.34],
       [ -7.19, -15.26,   2.8 ],
       [ -7.18, -13.96,  -2.34],
       [-11.79, -11.56,  -1.78],
       [ -9.98,  -9.72,   2.7 ],
       [ -5.11,  -9.93,   0.77],
       [ -6.94,  -7.83,  -3.62],
       [-10.44,  -5.39,  -0.48],
       [ -6.47,  -4.7 ,   2.97],
       [ -2.83,  -4.54,  -0.64],
       [ -6.1 ,  -1.78,  -3.58],
       [ -8.39,  -0.11,   0.87],
       [ -3.78,   0.37,   3.15],
       [ -2.34,   2.02,  -1.72],
       [ -6.69,   4.59,  -2.52],
       [ -7.42,   4.95,   2.63],
       [ -2.28,   6.26,   2.53],
       [ -2.86,   8.27,  -2.4 ],
       [ -7.65,  10.12,  -0.87],
       [ -5.42,  11.6 ,   3.6 ],
       [ -0.83,  11.88,   0.58],
       [  0.7 ,  16.76,  -0.88],
       [ -2.01,  15.79,  -5.8 ],
       [  5.78,  20.07,  -4.71],
       [  2.06,  24.34,  -4.58],
       [  6.84,  27.65,  -4.06]])

hull = ConvexHull(positions)

#Convert triangles to mesh coordinates.
mesh = positions[hull.simplices]
mesh = np.asarray(mesh).flatten().tolist() #everything has to be flatten
color = [[0,0,1]] * len(mesh) #blue
color = np.asarray(color).flatten().tolist()

view = nv.NGLWidget()
shape = view.shape
shape.add_mesh(mesh,color)
view.update_representation(component=0, repr_index=0, opacity=0.5 )
view

Спасибо за вашу помощь: -)

...