Messages from Loft operation

Need help, or want to share a macro? Post here!
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
edwilliams16
Veteran
Posts: 3182
Joined: Thu Sep 24, 2020 10:31 pm
Location: Hawaii
Contact:

Re: Messages from Loft operation

Post by edwilliams16 »

OK. I found a few bugs:

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
which is probably unnecessarily flexible.

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
It still doesn't quite work because of the recompute() problem. When I run under the debugger, with your FromFinger.csg or my rotated hulltwocones1.csg the code loops back to hull.execute I can't figure out the code to see what is happening, but there doesn't appear to be a test to show that the two objects have already been hulled. Since the algorithm will handle any number of collinear cones/cylinders, you need to change the logic anyway, which tests for two objects to be hulled.
Attachments
hulltwocones1.csg
(522 Bytes) Downloaded 5 times
edwilliams16
Veteran
Posts: 3182
Joined: Thu Sep 24, 2020 10:31 pm
Location: Hawaii
Contact:

Re: Messages from Loft operation

Post by edwilliams16 »

keithsloan52 wrote: Wed Apr 14, 2021 8:23 am ping
I got my ssh access to github working again. Somehow it had lost my public key.

I put the above mentioned fixes into my parallel_ew branch in https://github.com/edwilliams16/OpenSCAD_Alt_Import
I haven't figured out pull requests yet, so I'm letting you know here before you make more changes I need to merge!
The off-axis collinear cylinders now does the hull correctly, but I believe to recompute loop bug is what is screwing up the final axis rotation.
Screen Shot 2021-04-18 at 10.45.28 AM.png
Screen Shot 2021-04-18 at 10.45.28 AM.png (82.63 KiB) Viewed 350 times
It looks like you can now do multiple collinear cylinders/cones, but I haven't tested it yet.
keithsloan52
Veteran
Posts: 2764
Joined: Mon Feb 27, 2012 5:31 pm

Re: Messages from Loft operation

Post by keithsloan52 »

edwilliams16 wrote: Sun Apr 18, 2021 8:50 pm
keithsloan52 wrote: Wed Apr 14, 2021 8:23 am ping
The off-axis collinear cylinders now does the hull correctly, but I believe to recompute loop bug is what is screwing up the final axis rotation.Screen Shot 2021-04-18 at 10.45.28 AM.png

It looks like you can now do multiple collinear cylinders/cones, but I haven't tested it yet.
I came to that conclusion too and my copy of the code with your corrections is the same. The handling of a PartFeaturePython with dependent group ( Like a Boolean ) came from me making a request for a new facility and realthunder coming back and saying it can be done with current facilities, he produced the code and I already messaged him about the the invocation on import and a second invocation afterwards, he has not logged on since last Tuesday so will not have seen my message on current code. and test file, hope he is okay.
edwilliams16
Veteran
Posts: 3182
Joined: Thu Sep 24, 2020 10:31 pm
Location: Hawaii
Contact:

Re: Messages from Loft operation

Post by edwilliams16 »

In the meantime, I've developed an algorithm to find the convex hull of an arbitrary number of collinear spheres. As in the two sphere case we revolve the convex hull of a collection of semi-circles. The code is in https://github.com/edwilliams16/Convex_Hull_revolve

Run the plotdiagnostics.py file. It takes a list of circles on the z axis and returns a list of arcs and lines the constitutes the hull to revolve.
Here's a typical output, where the dashed lines are the (semi-) circles and the solid blue, the convex hull.

I'm still thinking about an arbitrary collection of coaxial cylinders, cones and spheres, which I think is the most you can do pursuing this line of attack.
Screen Shot 2021-04-20 at 11.49.16 AM.png
Screen Shot 2021-04-20 at 11.49.16 AM.png (34.59 KiB) Viewed 291 times
keithsloan52
Veteran
Posts: 2764
Joined: Mon Feb 27, 2012 5:31 pm

Re: Messages from Loft operation

Post by keithsloan52 »

edwilliams16 wrote: Tue Apr 20, 2021 9:51 pm In the meantime, I've developed an algorithm to find the convex hull of an arbitrary number of collinear spheres. As in the two sphere case we revolve the convex hull of a collection of semi-circles. The code is in https://github.com/edwilliams16/Convex_Hull_revolve

Run the plotdiagnostics.py file. It takes a list of circles on the z axis and returns a list of arcs and lines the constitutes the hull to revolve.
Here's a typical output, where the dashed lines are the (semi-) circles and the solid blue, the convex hull.

I'm still thinking about an arbitrary collection of coaxial cylinders, cones and spheres, which I think is the most you can do pursuing this line of attack.

Screen Shot 2021-04-20 at 11.49.16 AM.png
Many Thanks - Once again - I will give it some attention.
Post Reply