You are the author of the code. Do you wanna join the discussion?
Part API Euler Spirals?
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Be nice to others! Respect the FreeCAD code of conduct!
- HakanSeven12
- Veteran
- Posts: 1481
- Joined: Wed Feb 06, 2019 10:30 pm
Re: Part API Euler Spirals?
We have our own spiral object for trails. Take a look: https://github.com/joelgraff/freecad.tr ... /spiral.py
Support me: Hakan Seven on Patreon
Modern UI: Modern UI on FreeCAD Forum
Trails Workbench: Trails Workbench on FreeCAD Forum
Modern UI: Modern UI on FreeCAD Forum
Trails Workbench: Trails Workbench on FreeCAD Forum
- Joel_graff
- Veteran
- Posts: 1949
- Joined: Fri Apr 28, 2017 4:23 pm
- Contact:
Re: Part API Euler Spirals?
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.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?
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
pivy_trackers 2D coin3D library: https://www.github.com/joelgraff/pivy_trackers
- HakanSeven12
- Veteran
- Posts: 1481
- Joined: Wed Feb 06, 2019 10:30 pm
Re: Part API Euler Spirals?
up
Support me: Hakan Seven on Patreon
Modern UI: Modern UI on FreeCAD Forum
Trails Workbench: Trails Workbench on FreeCAD Forum
Modern UI: Modern UI on FreeCAD Forum
Trails Workbench: Trails Workbench on FreeCAD Forum
Re: Part API Euler Spirals?
Hi
Here is a basic python example (needs scipy) :
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
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)
And here is an interesting reading : An arc spline approximation to a clothoid
-
- Veteran
- Posts: 3106
- Joined: Thu Sep 24, 2020 10:31 pm
- Location: Hawaii
- Contact:
Re: Part API Euler Spirals?
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.Chris_G wrote: ↑Wed Jun 23, 2021 3:28 pm
And here is an interesting reading : An arc spline approximation to a clothoid
-
- Veteran
- Posts: 3106
- Joined: Thu Sep 24, 2020 10:31 pm
- Location: Hawaii
- Contact:
Re: Part API Euler Spirals?
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.
Re: Part API Euler Spirals?
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.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.
A Sketcher Lecture with in-depth information is available in English, auf Deutsch, en français, en español.
-
- Veteran
- Posts: 3106
- Joined: Thu Sep 24, 2020 10:31 pm
- Location: Hawaii
- Contact:
Re: Part API Euler Spirals?
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.
-
- Veteran
- Posts: 3106
- Joined: Thu Sep 24, 2020 10:31 pm
- Location: Hawaii
- Contact:
Re: Part API Euler Spirals?
I've figured out how to make it scalable, rotatable and translatable. I'll maybe try writing a macro.
Re: Part API Euler Spirals?
What are the input constraints ?
What is the intended workflow ?
Do you you want to fit it between existing curve segments ?
What is the intended workflow ?
Do you you want to fit it between existing curve segments ?