Part API Euler Spirals?

Need help, or want to share a macro? Post here!
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
User avatar
HakanSeven12
Veteran
Posts: 1481
Joined: Wed Feb 06, 2019 10:30 pm

Re: Part API Euler Spirals?

Post by HakanSeven12 »

We have our own spiral object for trails. Take a look: https://github.com/joelgraff/freecad.tr ... /spiral.py
Joel_graff wrote: Mon Jun 14, 2021 1:43 pm
You are the author of the code. Do you wanna join the discussion?
User avatar
Joel_graff
Veteran
Posts: 1949
Joined: Fri Apr 28, 2017 4:23 pm
Contact:

Re: Part API Euler Spirals?

Post by Joel_graff »

wmayer wrote: Mon Jun 14, 2021 1:48 pm While lines, circles or arcs are directly supported by OCCT this is not the case for Euler spirals. So, the only feasible way is to have a function that creates (an approximated) B-Spline curve from an Euler spiral. This function can be part of FreeCAD or a Python add-on. Are there any formulas to do the calculation?
This is a tricky question @microelly2 and I attempted to sort out a couple years ago. I wasn't able to get reliable performance from it. I admit, I'm no expert on splines, so it may be there's a way to get it done.

Otherwise, the solution involves Taylor series expansions and some fun integration to generate the more general Euler spiral with arbitrary start / end points (my code assumes the origin as one point). I did a proof-of-concept in a spreadsheet a couple years back, but it's a distant memory, now.
FreeCAD Trails workbench for transportation engineering: https://www.github.com/joelgraff/freecad.trails

pivy_trackers 2D coin3D library: https://www.github.com/joelgraff/pivy_trackers
User avatar
HakanSeven12
Veteran
Posts: 1481
Joined: Wed Feb 06, 2019 10:30 pm

Re: Part API Euler Spirals?

Post by HakanSeven12 »

up
User avatar
Chris_G
Veteran
Posts: 2578
Joined: Tue Dec 31, 2013 4:10 pm
Location: France
Contact:

Re: Part API Euler Spirals?

Post by Chris_G »

Hi

Here is a basic python example (needs scipy) :

Code: Select all

from scipy.special import fresnel
from numpy import linspace

def clothoid(fp, lp, num=100):
    t = linspace(fp, lp, num)
    pts = [FreeCAD.Vector(x,y,0) for y,x in zip(*fresnel(t))]
    poly = Part.makePolygon(pts)
    Part.show(poly)

clothoid(-5,5, 500)

Example script taken from : https://scipython.com/book/chapter-8-sc ... er-spiral/

And here is an interesting reading : An arc spline approximation to a clothoid
edwilliams16
Veteran
Posts: 3106
Joined: Thu Sep 24, 2020 10:31 pm
Location: Hawaii
Contact:

Re: Part API Euler Spirals?

Post by edwilliams16 »

Chris_G wrote: Wed Jun 23, 2021 3:28 pm
And here is an interesting reading : An arc spline approximation to a clothoid
Indeed interesting - approximating the clothoid by a sequence of equal length arcs with linearly changing curvature. This would be a straightforward sketcher macro if it were possible to put equal arclength constraints. I can see how to make them equal to a given arclength via expressions on the angle, but I don’t see how to make that length free to be computed by the sketcher solver. Maybe make them all equal to the length of a free construction line? I’ll see if I can make that work.
edwilliams16
Veteran
Posts: 3106
Joined: Thu Sep 24, 2020 10:31 pm
Location: Hawaii
Contact:

Re: Part API Euler Spirals?

Post by edwilliams16 »

Screen Shot 2021-06-23 at 2.23.28 PM.png
Screen Shot 2021-06-23 at 2.23.28 PM.png (11.86 KiB) Viewed 1802 times
Here's a clothoid - given initial and final radii, total arc-length and number of segments.

If there is any way to reference an unconstrained line length in a sketch in expressions, I could loosen up the dimensional degrees of freedom and make it a lot more useful, as you could then connect it up with the sketcher solver.
chrisb
Veteran
Posts: 53919
Joined: Tue Mar 17, 2015 9:14 am

Re: Part API Euler Spirals?

Post by chrisb »

edwilliams16 wrote: Thu Jun 24, 2021 12:29 am If there is any way to reference an unconstrained line length in a sketch in expressions, I could loosen up the dimensional degrees of freedom and make it a lot more useful, as you could then connect it up with the sketcher solver.
Yes, but not in the same sketch: you can use a driven (blue) constraint, which you can access via expression outside of the sketch, e.g. in another sketch.
A Sketcher Lecture with in-depth information is available in English, auf Deutsch, en français, en español.
edwilliams16
Veteran
Posts: 3106
Joined: Thu Sep 24, 2020 10:31 pm
Location: Hawaii
Contact:

Re: Part API Euler Spirals?

Post by edwilliams16 »

chrisb wrote: Thu Jun 24, 2021 7:12 am Yes, but not in the same sketch: you can use a driven (blue) constraint, which you can access via expression outside of the sketch, e.g. in another sketch.
This doesn't work for me. The sketch solver takes the current value of the length in the auxiliary sketch as a given constraint, not as a variable it can adjust to find a solution. The same would be the case if I referenced a spreadsheet or dynamic data.

If, for instance, I wanted to make a scale-invariant square in the Sketcher, I can set equality, vertical and horizontal constraints (but no dimensional ones). The resulting square can be translated and resized with the remaining degrees of freedom. These degrees can then be used by the solver to fit the square into a more complicated dimensioned figure.

I'm trying to make an Euler spiral whose length can be freely adjusted within the sketcher. This would be straightforward if two circular arcs could be given an equal length constraint. Absent that ability, I can make a bunch of radii all calculated multiples of a common length.
If I fix that length in any way the spiral's scale is locked down. I'm trying to make it a variable as far as the sketcher solver is concerned.

(BTW, I do have a inelegant solution in which I just approximate the arc lengths by the corresponding chord lengths. In the limit of tiny arcs the error is of the same quadratic order as the original approximation.)

The most versatile figure creation Sketcher Macros should be able to create figures that can be freely translated, rotated and scaled without changing shape. I'm not seeing how to do this without being able to set length ratios, or equivalently setting lengths a multiples of a length that is a sketcher solver variable.
edwilliams16
Veteran
Posts: 3106
Joined: Thu Sep 24, 2020 10:31 pm
Location: Hawaii
Contact:

Re: Part API Euler Spirals?

Post by edwilliams16 »

Euler1.gif
Euler1.gif (595.31 KiB) Viewed 1652 times
I've figured out how to make it scalable, rotatable and translatable. I'll maybe try writing a macro.
User avatar
Chris_G
Veteran
Posts: 2578
Joined: Tue Dec 31, 2013 4:10 pm
Location: France
Contact:

Re: Part API Euler Spirals?

Post by Chris_G »

What are the input constraints ?
What is the intended workflow ?
Do you you want to fit it between existing curve segments ?
Post Reply