File tree Expand file tree Collapse file tree 1 file changed +13
-9
lines changed
Expand file tree Collapse file tree 1 file changed +13
-9
lines changed Original file line number Diff line number Diff line change @@ -33,15 +33,19 @@ def _normal(cls, points):
3333 # first_index = 0
3434 # while first_index + 3 <= points.shape[0]:
3535 # print(first_index, points.shape[0])
36-
37- for idx in range (points .shape [0 ] - 3 ):
38- triangle = points [idx + 1 :idx + 3 ] - points [idx ]
39-
40- n = np .cross (triangle [0 ], triangle [1 ])
41- if normal is None :
42- normal = n
43- else :
44- normal += n if np .dot (normal , n ) > 0 else - n
36+
37+ if points .shape [0 ] == 3 :
38+ triangle = points [1 :3 ] - points [0 ]
39+ normal = np .cross (triangle [0 ], triangle [1 ])
40+ else :
41+ for idx in range (points .shape [0 ] - 3 ):
42+ triangle = points [idx + 1 :idx + 3 ] - points [idx ]
43+
44+ n = np .cross (triangle [0 ], triangle [1 ])
45+ if normal is None :
46+ normal = n
47+ else :
48+ normal += n if np .dot (normal , n ) > 0 else - n
4549
4650 return np .divide (normal , np .linalg .norm (normal ))
4751
You can’t perform that action at this time.
0 commit comments