Draw curve based on a function in Sketch(Part Design) Workbench

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!
dfosorio11
Posts: 36
Joined: Thu Sep 09, 2021 10:58 pm

Draw curve based on a function in Sketch(Part Design) Workbench

Post by dfosorio11 »

Hello dear community and developers,

I hope you are doing fine. I want to know how can I draw a curve in a XY plane based on a function (ie. exponential function) in the Sketcher (or Part Design) Workbech.
Big hugs

Diego
chrisb
Veteran
Posts: 53785
Joined: Tue Mar 17, 2015 9:14 am

Re: Draw curve based on a function in Sketch(Part Design) Workbench

Post by chrisb »

Hi Diego and welcome to the forum!

You cannot do it directly in Sketcher, but you can use addon macro "3D Parametric Curve" to create a draft object which then can be converted into a sketch.
A Sketcher Lecture with in-depth information is available in English, auf Deutsch, en français, en español.
TheMarkster
Veteran
Posts: 5505
Joined: Thu Apr 05, 2018 1:53 am

Re: Draw curve based on a function in Sketch(Part Design) Workbench

Post by TheMarkster »

I'm working on an update to that macro.

https://forum.freecadweb.org/viewtopic.php?f=22&t=61707
dfosorio11
Posts: 36
Joined: Thu Sep 09, 2021 10:58 pm

Re: Draw curve based on a function in Sketch(Part Design) Workbench

Post by dfosorio11 »

chrisb wrote: Fri Sep 10, 2021 7:23 am Hi Diego and welcome to the forum!

You cannot do it directly in Sketcher, but you can use addon macro "3D Parametric Curve" to create a draft object which then can be converted into a sketch.
Hello dear Chrisb

Thanks for your reply, it worked. I actually could manage to draw the parametric function curve into a draft. Now I want to convert this draft into an sketch object in order to work with it in the Part Design Workbench, and build a compound out of other parts from that parts planes/faces,etc
Big Hugs and thanks for the weloming

Diego
dfosorio11
Posts: 36
Joined: Thu Sep 09, 2021 10:58 pm

Re: Draw curve based on a function in Sketch(Part Design) Workbench

Post by dfosorio11 »

TheMarkster wrote: Fri Sep 10, 2021 2:34 pm I'm working on an update to that macro.

https://forum.freecadweb.org/viewtopic.php?f=22&t=61707
Hello dear Markster,

Awesome job. I will check up your videos on this macro upgrade.
Big hugs

Diego
TheMarkster
Veteran
Posts: 5505
Joined: Thu Apr 05, 2018 1:53 am

Re: Draw curve based on a function in Sketch(Part Design) Workbench

Post by TheMarkster »

dfosorio11 wrote: Fri Sep 10, 2021 3:15 pm
chrisb wrote: Fri Sep 10, 2021 7:23 am Hi Diego and welcome to the forum!

You cannot do it directly in Sketcher, but you can use addon macro "3D Parametric Curve" to create a draft object which then can be converted into a sketch.
Hello dear Chrisb

Thanks for your reply, it worked. I actually could manage to draw the parametric function curve into a draft. Now I want to convert this draft into an sketch object in order to work with it in the Part Design Workbench, and build a compound out of other parts from that parts planes/faces,etc
Big Hugs and thanks for the weloming

Diego
You can use the ParametricCurve object like you would a sketch. It can even be attached.


Suppose I want to get this curve into a Body:
Snip macro screenshot-3226ee.png
Snip macro screenshot-3226ee.png (58.04 KiB) Viewed 4204 times
Click on the Body. In the property view look for the Group property. Click it, and then the [...] button to bring up the editor. Select the ParametricCurve object to add it to the Body.
Snip macro screenshot-8acfff.png
Snip macro screenshot-8acfff.png (38.39 KiB) Viewed 4204 times
Snip macro screenshot-71c9bc.png
Snip macro screenshot-71c9bc.png (33.81 KiB) Viewed 4204 times
Now the ParametricCurve is in the Body. We can attach to one of the planes as we would a sketch, Pad it, whatever.
Snip macro screenshot-28433b.png
Snip macro screenshot-28433b.png (73.58 KiB) Viewed 4204 times
Of course, it must be 2D in order to use Pad with it. You can ensure this by setting the Z formula to 0 or some constant value or just leaving it blank.
dfosorio11
Posts: 36
Joined: Thu Sep 09, 2021 10:58 pm

Re: Draw curve based on a function in Sketch(Part Design) Workbench

Post by dfosorio11 »

Hi dear Markster!

Thanks a lot for your help. I did could mange to attach the 3D Parametric Curve object to the body. The problem is I can't edit the sketch or the Part in the solid directly, so I can't restrict the sketch with other lines, points, curves, etc to form a sketch to extrude. I tryed your attachment procedure in the Draft WB and the Sketch WB, but still could not get to build my 2D geometry for extrude.

The 3D parametric curve I am modeling is y(a,b,t)= a*exp(b*t), a=0,05 b=0,204 t=x , -12.33<t<0 (I attached pictures from the Vivaldi Broadband 3D model antenna I am trying to build), so the thing is this y(f) Parametric Curve is just a part of the 2D Sketch (or draft). I need to add the remaiding top and lower lines, and the vertical x-axis line, and the mirror the 2D sketch for extrude. I can visualize the 3D parametric curve but I can't unite it with the other lines.

Any ideas? I've been working with this antenna for 2 weeks and my boss is like killing me :((
Big hugs as always!

PS: Check the attached files to see the curves ;o)

Diego!
dfosorio11
Posts: 36
Joined: Thu Sep 09, 2021 10:58 pm

Re: Draw curve based on a function in Sketch(Part Design) Workbench

Post by dfosorio11 »

TheMarkster wrote: Fri Sep 10, 2021 9:11 pm
dfosorio11 wrote: Fri Sep 10, 2021 3:15 pm
chrisb wrote: Fri Sep 10, 2021 7:23 am Hi Diego and welcome to the forum!

You cannot do it directly in Sketcher, but you can use addon macro "3D Parametric Curve" to create a draft object which then can be converted into a sketch.
Hello dear Chrisb

Thanks for your reply, it worked. I actually could manage to draw the parametric function curve into a draft. Now I want to convert this draft into an sketch object in order to work with it in the Part Design Workbench, and build a compound out of other parts from that parts planes/faces,etc
Big Hugs and thanks for the weloming

Diego
You can use the ParametricCurve object like you would a sketch. It can even be attached.


Suppose I want to get this curve into a Body:

Snip macro screenshot-3226ee.png

Click on the Body. In the property view look for the Group property. Click it, and then the [...] button to bring up the editor. Select the ParametricCurve object to add it to the Body.

Snip macro screenshot-8acfff.png


Snip macro screenshot-71c9bc.png

Now the ParametricCurve is in the Body. We can attach to one of the planes as we would a sketch, Pad it, whatever.

Snip macro screenshot-28433b.png

Of course, it must be 2D in order to use Pad with it. You can ensure this by setting the Z formula to 0 or some constant value or just leaving it blank.
Attachments
im2.png
im2.png (130.83 KiB) Viewed 4096 times
im1.png
im1.png (161.4 KiB) Viewed 4096 times
TheMarkster
Veteran
Posts: 5505
Joined: Thu Apr 05, 2018 1:53 am

Re: Draw curve based on a function in Sketch(Part Design) Workbench

Post by TheMarkster »

To use Parametric_Curve_FP you must put the Parametric_Curve_FP.py file in your macros folder and also Make_Parametric_Curve.py into the same folder. Execute Make_Parametric_Curve to create the parametric curve fp object.

I entered the parameters you said, but I get a very flat curve. Perhaps I entered them wrong?
Snip macro screenshot-aa7471.png
Snip macro screenshot-aa7471.png (57.64 KiB) Viewed 4062 times
Snip macro screenshot-3b8ae3.png
Snip macro screenshot-3b8ae3.png (53.92 KiB) Viewed 4062 times
Snip macro screenshot-7bcf16.png
Snip macro screenshot-7bcf16.png (100.23 KiB) Viewed 4062 times
Attach a screenshot of your parameters as you have put them so I can see if they are the same that I used. Attach your file, too, if you can.

You can bring the bspline into your sketch as follows:

Use the link to external geometry tool (keyboard shortcut: X) in the sketch to create the external (purple) link.
Select the purple edge.
Sketch menu -> Sketcher bspline tools -> convert geometry to bspline

Now you have the curve into your sketch. You should be able to add coincidence constraints to the end points of the curve.

If the curve object is not inside the body (if using Part Design) you can create a shapebinder of it and use that with the external geometry.
edwilliams16
Veteran
Posts: 3079
Joined: Thu Sep 24, 2020 10:31 pm
Location: Hawaii
Contact:

Re: Draw curve based on a function in Sketch(Part Design) Workbench

Post by edwilliams16 »

dfosorio11 wrote: Sun Sep 12, 2021 10:51 pm The 3D parametric curve I am modeling is y(a,b,t)= a*exp(b*t), a=0,05 b=0,204 t=x , -12.33<t<0
You sure it's not 0<t<12.33? Origin in your figure is not at the right hand edge.
Post Reply