edwilliams16 wrote: ↑Fri Apr 16, 2021 5:40 pm
There's an endless list of successively more complicated configurations of primitives of which to find the convex hull. I assume you are trying to attack the use cases you are most concerned with?
Correct.
I have tried to implement based on your code. (Changed to sort for z-cord i.e. object heights)
But not quite working on my test file gets points i.e. what is passed as coordList
[Vector (0.0, 0.0, -2.0), Vector (0.0, 9.25, -2.0), Vector (0.0, 9.25, 0.0), Vector (0.0, 0.0, -40.0), Vector (0.0, 11.9, -40.0), Vector (0.0, 10.0, -4.0)]
top gets reduced to [Vector (0.0, 0.0, -40.0), Vector (0.0, 9.25, 0.0)] which is not correct
Code: Select all
def createFace(coordList) :
points = sorted(coordList, key = lambda x: x[2]) # sort by z-coord
top = [points[0], points[1]]
for p in points[2:]:
top.append(p)
while len(top) > 2 and not _isConvex(*top[-3:]):
del top[-2]
print(top)
#poly = Part.makePolygon(top)
#face = Part.makeFace(poly)
#face = Part.makeFace(top)
#return face
def _isConvex(p, q, r):
'return True if the vectors pq to qr is a right turn ie convex'
return q[0]*r[1] + p[0]*q[1] + r[0]*p[1] - \
(q[0]*p[1] + r[0]*q[1] + p[0]*r[1]) < 0
Full code is at
https://github.com/KeithSloan/OpenSCAD_Alt_Import
branch parallel
Test file