Stretching shapes

Post here for help on using FreeCAD's graphical user interface (GUI).
Forum rules
and Helpful information
IMPORTANT: Please click here and read this first, before asking for help

Also, be nice to others! Read the FreeCAD code of conduct!
JR

Stretching shapes

Postby JR » Sun Jun 12, 2011 8:56 pm

Hi,

I would like to make a shape that is a circle in the bottom and an ellipse on the top. I thought of making it by making a cylinder and then stretching one of its faces in one direction, but I don't seem to find that option. How would you use FreeCAD to make this shape? Thanks very much in advance. JR
wmayer
Site Admin
Posts: 14043
Joined: Thu Feb 19, 2009 10:32 am

Re: Stretching shapes

Postby wmayer » Tue Jun 14, 2011 9:39 am

With the GUI you currently can't do it but it's possible via Python scripting. Here is the code snippet you can use:

Code: Select all

import Part
from FreeCAD import Base

c=Part.makeCircle(5.0,Base.Vector(0,0,0))
e=Part.makeCircle(5.0,Base.Vector(0,0,10))
m=Base.Matrix()
m.A11=2.0
e=e.transformGeometry(m)
cw=Part.Wire(c)
ew=Part.Wire(e)
l=Part.makeLoft([cw,ew])
Part.show(l)
As you can see the trick to make an ellipse is by stretching a circle and to make the surface is done by makeLoft().
JR

Re: Stretching shapes

Postby JR » Thu Jun 16, 2011 11:24 am

wmayer,

Thank you very much. How do I make this surface into a filled solid? I tried for a bit using the makeSolid command from the Part API (http://sourceforge.net/apps/mediawiki/f ... e=Part_API) but I wasn't able to get it.

JR
wmayer
Site Admin
Posts: 14043
Joined: Thu Feb 19, 2009 10:32 am

Re: Stretching shapes

Postby wmayer » Thu Jun 16, 2011 1:18 pm

Code: Select all

import Part
from FreeCAD import Base

c=Part.makeCircle(5.0,Base.Vector(0,0,0))
e=Part.makeCircle(5.0,Base.Vector(0,0,10))
m=Base.Matrix()
m.A11=2.0

bot=Part.Face(Part.Wire(c))
top=Part.Face(Part.Wire(e))
top=Part.Face(top.transformGeometry(m))

e=e.transformGeometry(m)
cw=Part.Wire(c)
ew=Part.Wire(e)
l=Part.makeLoft([cw,ew])
shell=Part.Shell(l.Faces)
shell.add(top)
shell.add(bot)
solid=Part.Solid(shell)
Part.show(solid)
wmayer
Site Admin
Posts: 14043
Joined: Thu Feb 19, 2009 10:32 am

Re: Stretching shapes

Postby wmayer » Thu Jun 16, 2011 1:24 pm

The loft function of our cad kernel also offers a parameter to build directly a solid. So, I have now added an optional parameter (default: False) to makeLoft() to create directly the solid. This change will be available with the next release, then.
JR

Re: Stretching shapes

Postby JR » Thu Jun 16, 2011 2:26 pm

Excellent, thank you very much. Thanks for the feature addition too.
User avatar
NormandC
Posts: 18534
Joined: Sat Feb 06, 2010 9:52 pm
Location: Québec, Canada

Re: Stretching shapes

Postby NormandC » Sun Jun 19, 2011 7:06 am

wmayer wrote:I have now added an optional parameter (default: False) to makeLoft() to create directly the solid. This change will be available with the next release, then.
Hi Werner,

How do we set the parameter to true in Python to create the solid directly?

Thanks!
jr22
Posts: 18
Joined: Sun Jun 19, 2011 7:02 pm

Re: Stretching shapes

Postby jr22 » Sun Jun 19, 2011 7:56 pm

wmayer,

The solid you made from the stretched circle and the normal circle works pretty well when trying to apply boolean operations (cut, fuse, common, ...etc.). I tried my own version of that, trying to make a solid between a circle and a rectangle, and while it looks pretty swell, it will not work for boolean operations, so there must be something wrong with it. Is there something I am missing? Or I am just asking the loft/solid commands too much? Thank you very much. Here is my version of your code:

Code: Select all

import Part
from FreeCAD import Base
# make a circle and a rectangle
c=Part.makeCircle(5.0,Base.Vector(0,0,0))
e=Part.makePolygon([Base.Vector(-8,-2,-8),Base.Vector(8,-2,-8),Base.Vector(8,2,-8),Base.Vector(-8,2,-8),Base.Vector(-8,-2,-8)])
# make shapes into wires
cw=Part.Wire(c)
ew=Part.Wire(e)
# make faces from wires
bot=Part.Face(cw)
top=Part.Face(ew)
# make loft
l=Part.makeLoft([cw,ew])
# make shell from loft's faces
shell=Part.Shell(l.Faces)
# add top and bottom to make closed shell
shell.add(top)
shell.add(bot)
# make into a solid and close
solid=Part.Solid(shell)
Part.show(solid)
wmayer
Site Admin
Posts: 14043
Joined: Thu Feb 19, 2009 10:32 am

Re: Stretching shapes

Postby wmayer » Mon Jun 20, 2011 9:07 am

normandc wrote:
wmayer wrote:I have now added an optional parameter (default: False) to makeLoft() to create directly the solid. This change will be available with the next release, then.
Hi Werner,

How do we set the parameter to true in Python to create the solid directly?

Thanks!

Code: Select all

import Part
from FreeCAD import Base

c=Part.makeCircle(5.0,Base.Vector(0,0,0))
e=Part.makeCircle(5.0,Base.Vector(0,0,10))
m=Base.Matrix()
m.A11=2.0

e=e.transformGeometry(m)
cw=Part.Wire(c)
ew=Part.Wire(e)
l=Part.makeLoft([cw,ew],True) ## <<<============
shell=Part.Shell(l.Faces)
solid=Part.Solid(shell)
Part.show(solid)
wmayer
Site Admin
Posts: 14043
Joined: Thu Feb 19, 2009 10:32 am

Re: Stretching shapes

Postby wmayer » Mon Jun 20, 2011 9:19 am

The solid you made from the stretched circle and the normal circle works pretty well when trying to apply boolean operations (cut, fuse, common, ...etc.). I tried my own version of that, trying to make a solid between a circle and a rectangle, and while it looks pretty swell, it will not work for boolean operations, so there must be something wrong with it. Is there something I am missing? Or I am just asking the loft/solid commands too much? Thank you very much. Here is my version of your code:
Indeed your shape is broken. When selecting the object and setting "Lightning" to "One side" in the property editor you'll see that your shape is inverted, i.e. it has the wrong orientation and thus appears black. Since boolean operations must rely on a proper orientation it will (often) fail if it's incorrect. To fix this just call this additional line:

Code: Select all

solid.reverse()
Nevertheless, IMO boolean operations is still one of the weakest points of the actually great OCC kernel. It is a constant point of trouble where it often fails with rather simple models.