Parabola, scripts and parameters

Need help, or want to share a macro? Post here!
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
ketilfroyn
Posts: 18
Joined: Tue Jan 29, 2013 11:47 am

Parabola, scripts and parameters

Post by ketilfroyn »

Hi,

I'm trying to create a parabolic solid. I've run into a few issues on the way that I didn't figure out quite how to solve. To create the parabola itself, I laid aside my reservations about using the freecad scripting interface, and went ahead with the short script from here:

viewtopic.php?f=3&t=137

The script looks like:

Code: Select all

import Part, math

# create a parabola
parabola=Part.Parabola()
# rotate the curve around the x-Axis and the origin (0,0,0)
revol=Part.SurfaceOfRevolution(parabola,App.Vector(0,0,0),App.Vector(1,0,0))
# create a shape out of the surface geometry in order to make it visible
shape=revol.toShape(0,math.pi, -5, 5)
Part.show(shape)
I aim to 3D print this part, so I want it to face upwards (Z axis), but the one in this example has the "opening" of the parabola pointing along the X axis. I've been playing around with the parameters to SurfaceOfRevolution() as well as variables like parabola.Axis, parabola.Focus, but I've not been able to make the parabola point the right way (I mostly get a saddle-like shape instead), and I've been unable to find documentation for the parameters to these methods.

However, if I leave the parabola "on its side" as it is, I can always transform it later, or even rotate the mesh in blender before printing. But what's the best way to create a solid of a given thickness from this shape? I tried Part -> Extrude with X=1, Y=0, Z=0, Length=2, Along normal=False, Create solid=True, Taper angle=0. When I export the resulting solid as an STL, that STL is not manifold, so it doesn't seem to be well formed. I tried creating two parabolas where one was shifted a bit, and creating a solid using Part -> Loft, but the resulting STL is still non-manifold, for the same reason.

I'd appreciate any suggestions on what I might do to work around these issues, other than repairing the STL in blender afterwards, which is an option, but not ideal.
User avatar
bejant
Veteran
Posts: 6075
Joined: Thu Jul 11, 2013 3:06 pm

Re: Parabola, scripts and parameters

Post by bejant »

ketilfroyn
Posts: 18
Joined: Tue Jan 29, 2013 11:47 am

Re: Parabola, scripts and parameters

Post by ketilfroyn »

Thanks, I was able to rotate it like that. Better to do it here than in Blender later! :) Though hopefully it should be possible to create the parabola at a different angle in the first place, to avoid transforms when scripting to create several complex shapes.

Do you know how I can make a solid out of it? With all the methods I've tried to make a solid, I've ended up with an internal plane along the original curve that "slices" through the solid, and that's why the STL is not manifold.
User avatar
bejant
Veteran
Posts: 6075
Joined: Thu Jul 11, 2013 3:06 pm

Re: Parabola, scripts and parameters

Post by bejant »

ketilfroyn wrote:Do you know how I can make a solid out of it?
Sorry but I'm learning myself and don't know how to do that yet. So after someone else replies, we'll both know!
eivindkvedalen
Posts: 602
Joined: Tue Jan 29, 2013 10:35 pm

Re: Parabola, scripts and parameters

Post by eivindkvedalen »

Try adding

shape.Placement = App.Placement(App.Vector(0,0,0),App.Rotation(0,0.707107,0,-0.707107))

before you show the part.

Eivind
wmayer
Founder
Posts: 20243
Joined: Thu Feb 19, 2009 10:32 am
Contact:

Re: Parabola, scripts and parameters

Post by wmayer »

Be careful with the use of SurfaceOfRevolution because this does always do a full revolution of 360 deg. However, a parabola is a symmetric curve and theoretically an angle of 180 deg would suffice. An alternative is to create an edge of only the right "branch" of the curve and than use the revolve() method. This automatically resolves the non-manifold problem.
I aim to 3D print this part, so I want it to face upwards (Z axis), but the one in this example has the "opening" of the parabola pointing along the X axis.
You can set the axis of the curve, the axis is the normal of the plane where the parabola is lying on. It appeared that setting an axis of (0,1,0) does what you want.

Code: Select all

import Part, math

# create a parabola
parabola=Part.Parabola()
# the axis of the plane the curve is lying on, this sets the symmetry axis to (0,0,1)
parabola.Axis=App.Vector(0,1,0)
# get only the right part of the curve
edge=parabola.toShape(0,5)
face=edge.revolve(App.Vector(0,0,0),App.Vector(0,0,1),360)
Part.show(face)
Do you know how I can make a solid out of it? With all the methods I've tried to make a solid, I've ended up with an internal plane along the original curve that "slices" through the solid, and that's why the STL is not manifold.
The extrude command doesn't work in this case because it moves the shape along one direction but you rather need some kind of offset.
So, one way might be to create an offset shape

Code: Select all

offset=face.makeOffsetShape(-1.0,0.001)
and create two solids of them using the shape builder from the Part menu (it needs quite some clicking). At the end you can do a boolean cut to have a thickness.


EDIT: Setting the axis to (0,1,0) of the parabola doesn't necessarily lead to a symmetry axis of (0,0,1). If often becomes (1,0,0) instead. So, with the current API there is no way to force a certain symmetry axis.

EDIT2: A default parabola has the symmetry axis (1,0,0) and the axis (0,0,1). To force a symmetry axis of (0,0,1) we have to rotate around the y-axis by -90 deg.

Code: Select all

m=App.Matrix()
m.rotateY(math.radians(-90))
parabola=Part.Parabola()
parabola.transform(m)
Part.show(parabola.toShape(-5,5))
wmayer
Founder
Posts: 20243
Joined: Thu Feb 19, 2009 10:32 am
Contact:

Re: Parabola, scripts and parameters

Post by wmayer »

An easier way to create a solid is by adding the line to the parabola and revolve that. Then you automatically get a closed shell which can be easily converted to a solid. Afterwards you can apply a thickness. Below is a script that does all this:

Code: Select all

import Part, math

m=App.Matrix()
m.rotateY(math.radians(-90))
# create a parabola with the symmetry axis (0,0,1)
parabola=Part.Parabola()
parabola.transform(m)

# get only the right part of the curve
edge=parabola.toShape(0,5)

# add a line to the parabola to get a closed revolution body
pt=parabola.value(5)
line=Part.makeLine(pt,App.Vector(0,0,pt.z))
wire=Part.Wire([edge,line])
shell=wire.revolve(App.Vector(0,0,0),App.Vector(0,0,1),360)

# make a solid
solid=Part.Solid(shell)

# apply a thickness, solid.Faces[1] is the plane that gets removed therefore
thick=solid.makeThickness([solid.Faces[1]],-1.0,0.001) # a thickness of -1
Part.show(thick)
ketilfroyn
Posts: 18
Joined: Tue Jan 29, 2013 11:47 am

Re: Parabola, scripts and parameters

Post by ketilfroyn »

Thanks, that seems to have worked nicely. I used your script which presumably creates some faces, and then I used Part -> "Advanced utility to create shapes" in the GUI to first create a shell from the faces, and then create a solid from the shape. I exported that solid as an STL, and it has created a perfect manifold mesh. Thanks for the help!

Still haven't quite worked out the documentation, so I haven't quite worked out stuff like Part.toShape() method, and stuff like Part.Wire(), but I'm very new to this so I'll try to keep at it.
kscheff
Posts: 4
Joined: Wed May 20, 2015 6:26 pm

Re: Parabola, scripts and parameters

Post by kscheff »

Hi, I am looking to use the parabola with some parameters rather then the standard -5 to 5 size.
Specifically I wanted to design parabola antenna where I need to input:

D: diameter
H: height
F: Focal distance

I have no trouble programming in Python, however I am struggling with the 3D geometry engine and how to use it...
Any help here would be highly appreciated.
User avatar
DeepSOIC
Veteran
Posts: 7896
Joined: Fri Aug 29, 2014 12:45 am
Location: used to be Saint-Petersburg, Russia

Re: Parabola, scripts and parameters

Post by DeepSOIC »

You can use a huge sketcher ellipse as a good approximation of a parabola. Just throw the other focus very far, say, 300m.
Post Reply