Flatten a face

Need help, or want to share a macro? Post here!
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
User avatar
Chris_G
Veteran
Posts: 2602
Joined: Tue Dec 31, 2013 4:10 pm
Location: France
Contact:

Flatten a face

Post by Chris_G »

Hi,
I wanted to share a little trick.
A friend asked me if it was possible to flatten a face.
His version of SolidWorks didn't offer this feature.
This is a thin sheet of metal that is bent around a center block :
flatten-1.jpg
flatten-1.jpg (11.6 KiB) Viewed 6911 times
He wanted to get the shape of this flattened face, to cut it to shape before bending it.
Here is how I did it:
I discretized the profile curve with distance method :

Code: Select all

bspline.discretize(Distance = 0.2)
flatten-2.jpg
flatten-2.jpg (7.63 KiB) Viewed 6911 times
Then I created a curvilinear knot sequence :

Code: Select all

# pts are the discretized points
# dis is the discretization distance
params = []
for i in range(len(pts)):
    params.append(1.0 * i * dis)
Then I created an interpolating curve from these points and parameters

Code: Select all

bs = Part.BSplineCurve()
bs.interpolate(Points = pts, Parameters = params)
This way, for any point on the curve, its parameter is the distance from curve start.
Then I extruded the resulting curve :
flatten-3.jpg
flatten-3.jpg (10.36 KiB) Viewed 6911 times
The extruding operation also creates a curvilinear parametrization in the V direction.
So the parameters of this surface match realworld units.
Then I made the boolean operations to give the surface its final shape :
flatten-4.jpg
flatten-4.jpg (10.69 KiB) Viewed 6911 times
And it is now simply a matter of taking the 2d curves of all the edges of this face and "apply" them an a plane :

Code: Select all

#face is the face highlighted above
edges = face.Edges

# the list of 2D curves
curves2d = [] 
for e in edges:
    curves2d.append(face.curveOnSurface(e))

# apply the 2D curves on a plane
plane = Part.Plane()
for c in curves2d:
    Part.show(c[0].toShape(plane))
And here is the flattened face :
flatten-5.jpg
flatten-5.jpg (8.59 KiB) Viewed 6911 times
In case someone needs this one day ...
Chris
User avatar
microelly2
Veteran
Posts: 4688
Joined: Tue Nov 12, 2013 4:06 pm
Contact:

Re: Flatten a face

Post by microelly2 »

Yes, its a nice and useful trick.
having linear and parallel vIso/uIso curves the surface is developeable.
this is a "generalized cylinder".
with some more calculation this can be adapted to "generalized cones" too (vIso curves are lines and go all to throught the same point)

For me the question is: How to detect areas on a surface that are cylinder or cone like.
the theory is obvious the principal curvature must be zero, so one has to find the areas with curvature 0 to get developable subsurfaces.

thanks for the tipp.
Mark Szlazak
Posts: 439
Joined: Tue Apr 04, 2017 6:06 pm
Location: SF Bay Area, California

Re: Flatten a face

Post by Mark Szlazak »

Thanks Chris!

This gave me an idea for a CAD challenge. It's a reverse of what you did.
If you start with a flat plane in CAD then can you fold it with CAD operations to make some origami?

This was made from a single sheet of paper.
Origami_spring.jpg
Origami_spring.jpg (224.52 KiB) Viewed 6892 times
User avatar
microelly2
Veteran
Posts: 4688
Joined: Tue Nov 12, 2013 4:06 pm
Contact:

Re: Flatten a face

Post by microelly2 »

Mark Szlazak wrote: Fri Jun 16, 2017 6:59 pm This gave me an idea for a CAD challenge. It's a reverse of what you did.
If you start with a flat plane in CAD then can you fold it with CAD operations to make some origami?
this task is solved partially by the sheet metal workbench.
you start with a planar sheet and fold it to a shell.
at the moment there is no support for rolling the plane to a cylinder or a cone
it's an interesting task too

for paper work I have this macro
freecadbuch.de/doku.php?id=blog:papiermodelle_erstellen

of course origami is a nice task, but the main problem is to unroll/unfold a Shell.
If the way to unroll it is found you can bend and roll back from the plane to the volume going the trace back.
Jee-Bee
Veteran
Posts: 2566
Joined: Tue Jun 16, 2015 10:32 am
Location: Netherlands

Re: Flatten a face

Post by Jee-Bee »

microelly2 wrote: Fri Jun 16, 2017 7:53 pm at the moment there is no support for rolling the plane to a cylinder or a cone
it's an interesting task too
As far as i remember it isn't in Pro-E Creo (or i didn't know it) but in Creo there is one verry nice sheet metal feature and that is convert to sheet metal and that works well with cilindrical sheet metal
Leatherman
Posts: 155
Joined: Thu Feb 02, 2017 2:49 pm

Re: Flatten a face

Post by Leatherman »

Thank you for sharing!
bennn
Posts: 23
Joined: Thu Jul 21, 2016 7:15 am

Re: Flatten a face

Post by bennn »

Hi all,

I took inspiration from Chris and created this little macro that unrolls a face or solid. This is more oriented toward wood/foam machining, for snowboard or kiteboard core manufacturing for instance.

Let me know what you think. If people find it useful I'll add it to the wiki.

This is my first Freecad macro, so I'm definitely open to criticism !
Attachments
unfoldSheet.py
macro
(3.43 KiB) Downloaded 218 times
TheMarkster
Veteran
Posts: 5513
Joined: Thu Apr 05, 2018 1:53 am

Re: Flatten a face

Post by TheMarkster »

bennn wrote: Fri Aug 10, 2018 3:23 pm Hi all,

I took inspiration from Chris and created this little macro that unrolls a face or solid. This is more oriented toward wood/foam machining, for snowboard or kiteboard core manufacturing for instance.

Let me know what you think. If people find it useful I'll add it to the wiki.

This is my first Freecad macro, so I'm definitely open to criticism !
Looks interesting. Can you upload a simple model demonstrating its use?
bennn
Posts: 23
Joined: Thu Jul 21, 2016 7:15 am

Re: Flatten a face

Post by bennn »

If you open that project attached, you'll find a bent volume, generated with bezier surfaces.

If you select all edges that need flattening, which are the edges along x axis, starting with the reference edge, which is one of those that are supposed to be flat - typically the bottom ones if you want to cnc a part -, and run the macro, you'll get a flat part.

Let me know if that works !
Attachments
unfoldSheetExample.fcstd
(9.03 KiB) Downloaded 138 times
TheMarkster
Veteran
Posts: 5513
Joined: Thu Apr 05, 2018 1:53 am

Re: Flatten a face

Post by TheMarkster »

I had to add these 2 lines to the import section:

Code: Select all

import numpy
from FreeCAD import Base
Otherwise I was getting the message about selecting the edges, which was masking the real issue (numpy and Base being undefined).

One thing I was interested in was flattening out this object just to see if it would give me a better way to judge the uniformity of the groove.
cam-groove.png
cam-groove.png (17.67 KiB) Viewed 5789 times
I was able to get these 2 faces:
cam-groove-faces.png
cam-groove-faces.png (5.84 KiB) Viewed 5789 times
which I got by selecting the 2 innermost edges and running the macro twice, swapping the order of selection each time. It didn't really help me as far as determining whether the groove was uniform, but an interesting result all the same.

As to how useful the macro would be for its intended purpose I'm not the one to judge because I don't do that sort of work.
Post Reply