You are now constructing the rotatable polygon along the z-axis with the radial dimension along y, which I think is clearer. So, now
1) we sort the points along the z-axis
2) since z and y are taking the roles of x and y, the _isConvex test gets reversed
I used
Code: Select all
def createRevolveHull(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:],2, 1):
del top[-2]
#print(top)
# close polygon
top.append(top[0])
poly = Part.makePolygon(top)
revHull = poly.revolve(FreeCAD.Vector(0,0,0),FreeCAD.Vector(0,0,1),360)
return revHull
def _isConvex(p, q, r, ind1, ind2):
'return True if the vectors pq to qr is a right turn ie convex. ind1 is sort axis. ind2 the other'
return q[ind1]*r[ind2] + p[ind1]*q[ind2] + r[ind1]*p[ind2] - \
(q[ind1]*p[ind2] + r[ind1]*q[ind2] + p[ind1]*r[ind2]) < 0
We also need to rotate the hull axis onto that of the collinear objects.
Code: Select all
revHull = createRevolveHull(pointLst)
revHull.Placement.Rotation = obj1.Placement.Rotation # rotate from z-axis to collinear axis
return revHull