sweep along any path
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Be nice to others! Respect the FreeCAD code of conduct!
sweep along any path
Dear all,
I have a path defined by many points defined in a file and want to sweep a 2d shape like the circle along this path. Is there any example illustrating how to achieve this? I searched a lot and could not find such an example. Thank you in advance.
I have a path defined by many points defined in a file and want to sweep a 2d shape like the circle along this path. Is there any example illustrating how to achieve this? I searched a lot and could not find such an example. Thank you in advance.
Re: sweep along any path
Hi and welcome to the forum!
You have two issues here: Create a path from a set of points, and creating a sweep from this path. The latter is well known and described in PartDesign AdditivePipe.
The former needs probably some python knowledge, so I would recommend to move this post to the Python subforum.
You have two issues here: Create a path from a set of points, and creating a sweep from this path. The latter is well known and described in PartDesign AdditivePipe.
The former needs probably some python knowledge, so I would recommend to move this post to the Python subforum.
A Sketcher Lecture with in-depth information is available in English, auf Deutsch, en français, en español.
Re: sweep along any path
Dear chrisb,
Thanks for your help. I formed the sweep path from the points using BSplineCurve. However part design reported the error "TopoDS:Wire" when I did sweep. I'm new to freecad. Could you tell me how to handle with this problem? I also attached the freecad file and the points file.
Thanks for your help. I formed the sweep path from the points using BSplineCurve. However part design reported the error "TopoDS:Wire" when I did sweep. I'm new to freecad. Could you tell me how to handle with this problem? I also attached the freecad file and the points file.
- Attachments
-
- v_pole.txt
- (22.27 KiB) Downloaded 45 times
-
- sweep.FCStd
- (66.54 KiB) Downloaded 46 times
Re: sweep along any path
Preliminary remark: CopyShape must lie inside of the body, but that is not the origin of the problem.
I'm not sure what the problem is. I have attached the circle with normal to edge mode to the path and I made the section smaller, both to no avail. Perhaps it is a mere volume issue with the 302 control points. I have also observed that the control polygon isn't as smooth as usual, but rather jagged: I have also tried several methods from Curves workbench (discretize, interpolate) with the same result as before. I could not discretize the B-spline to see if at least an initial segment would work. Perhaps @Chris_G, the author of the great Curves workbench can help.
I'm not sure what the problem is. I have attached the circle with normal to edge mode to the path and I made the section smaller, both to no avail. Perhaps it is a mere volume issue with the 302 control points. I have also observed that the control polygon isn't as smooth as usual, but rather jagged: I have also tried several methods from Curves workbench (discretize, interpolate) with the same result as before. I could not discretize the B-spline to see if at least an initial segment would work. Perhaps @Chris_G, the author of the great Curves workbench can help.
A Sketcher Lecture with in-depth information is available in English, auf Deutsch, en français, en español.
Re: sweep along any path
Code: Select all
"""Sweep using a BSpline.
file: 20220606-sweep.py
Author: Carlo Dormeletti
Copyright: 2022
Licence: LGPL
"""
# import math
import os
import FreeCAD
import FreeCADGui
from FreeCAD import Vector, Rotation, Placement# noqa
import Part # noqa
DOC = FreeCAD.ActiveDocument
def create_points(filename):
points = []
with open(filename,'r') as f:
data = f.readlines()
for line in data:
line.strip()
coords = [float(x) for x in line.split()]
points.append(Vector(*coords))
return points
def do_sweep(points):
bs = Part.BSplineCurve()
bs.buildFromPoles(points, False)
path = DOC.addObject("Part::Feature", "path")
path.Shape = bs.toShape()
DOC.recompute()
rad = 1.0
circle = Part.Circle(Vector(0, 0, 0), Vector(0, 0, 1), rad)
prof_dsp = Vector(0, 01.194835164932913862e+0, 0) + Vector(0, rad * 1, 0)
profile = DOC.addObject("Part::Feature", "profile")
profile.Shape = circle.toShape()
profile.Placement = Placement(prof_dsp, Rotation(0, 0, 0))
DOC.recompute()
sw_solid = DOC.addObject("Part::Sweep", "sweep")
sw_solid.Sections = (profile)
sw_solid.Spine = path
sw_solid.Solid = False
sw_solid.Frenet = False
DOC.recompute()
points = create_points("v_pole.txt")
print(f"From: {points[0]} to: {points[-1]}")
do_sweep(points)
Probably the simple sweep is not enough as the bspline is changing directions, I have tried to place the bspline used as a path near an "edge" of the circle, but the change of curvature made the sweep to rotate the cricle and obtain this:
Numbers are very small, so it is diffcult to tune things, a 1mm radius circle is used in the scripts.
BSpline is constructed in YZ plane as the X values are all 0.0, and are very small, 300 value from Vector (0.0, 1.1948351649329139, 0.0) to Vector (0.0, 0.9191039730253182, 0.75) maybe are too much.
It use v_poles.txt placed in user directory at least on Linux, probably a fullpath as name will be more correct in:
Code: Select all
points = create_points("v_pole.txt")
Regards
Carlo D.
GitHub page: https://github.com/onekk/freecad-doc.
- In deep articles on FreeCAD.
- Learning how to model with scripting.
- Various other stuffs.
Blog: https://okkmkblog.wordpress.com/
- In deep articles on FreeCAD.
- Learning how to model with scripting.
- Various other stuffs.
Blog: https://okkmkblog.wordpress.com/
Re: sweep along any path
Thank you very much. However freeCAD eated up 8G memory of my computer when I executed the script and the software crashed.
Re: sweep along any path
Usually sweep is delicate and some caveats has to be used.
As @chrisb as told you a script is probably the best way when dealing with something produced by other programs, as you could manage better with the "power of python" object creation.
Using 300 point for a 10mm path maybe is too much, there are other ways to do this sort of things.
Using the sweep tool you have a limited "degree of freedom" to manage the way the profile is "traveling" along the "path".
There are more complex way to manage things, I have had a problem similar to this, and this the forum discussion:
BRepOffsetAPI.makePipeShell usage
https://forum.freecadweb.org/viewtopic.php?f=22&t=65467
This is loosely related, but maybe it has some hints about other things:
Use of Geom2D and Part.BRepOffsetAPI.MakePipeShell() to make Threads
https://forum.freecadweb.org/viewtopic.php?f=22&t=65875
Hope it helps.
Regards
Carlo D.
GitHub page: https://github.com/onekk/freecad-doc.
- In deep articles on FreeCAD.
- Learning how to model with scripting.
- Various other stuffs.
Blog: https://okkmkblog.wordpress.com/
- In deep articles on FreeCAD.
- Learning how to model with scripting.
- Various other stuffs.
Blog: https://okkmkblog.wordpress.com/
-
- Veteran
- Posts: 3194
- Joined: Thu Sep 24, 2020 10:31 pm
- Location: Hawaii
- Contact:
Re: sweep along any path
I down-sampled @onekk's script and made the circle smaller. It's problematic when the radius of curvature of the profile is smaller than the profile radius. I also moved the sweep path to the circle center. The result looks OK.
Code: Select all
"""Sweep using a BSpline.
file: 20220606-sweep.py
Author: Carlo Dormeletti
Copyright: 2022
Licence: LGPL
"""
# import math
import os
import FreeCAD
import FreeCADGui
from FreeCAD import Vector, Rotation, Placement# noqa
import Part # noqa
DOC = FreeCAD.ActiveDocument
def create_points(filename):
points = []
with open(filename,'r') as f:
data = f.readlines()
for line in data:
line.strip()
coords = [float(x) for x in line.split()]
points.append(Vector(*coords))
return points
def do_sweep(points):
bs = Part.BSplineCurve()
bs.buildFromPoles(points, False)
path = DOC.addObject("Part::Feature", "path")
path.Shape = bs.toShape()
DOC.recompute()
rad = 0.1
circle = Part.Circle(Vector(0, 0, 0), Vector(0, 0, 1), rad)
prof_dsp = Vector(0, 01.194835164932913862e+0, 0) #+ Vector(0, rad * 1, 0)
profile = DOC.addObject("Part::Feature", "profile")
profile.Shape = circle.toShape()
profile.Placement = Placement(prof_dsp, Rotation(0, 0, 0))
DOC.recompute()
sw_solid = DOC.addObject("Part::Sweep", "sweep")
sw_solid.Sections = (profile)
sw_solid.Spine = path
sw_solid.Solid = False
sw_solid.Frenet = False
DOC.recompute()
points = create_points("/Users/ed/Downloads/v_pole.txt")
print(f"From: {points[0]} to: {points[-1]}")
step = 5
points_s = points[::step]
points_s.append(points[-1])
do_sweep(points_s)
Re: sweep along any path
down sampled my script or the points?edwilliams16 wrote: ↑Mon Jun 06, 2022 6:59 pm I down-sampled @onekk's script and made the circle smaller.
Sorry I'm confused with all these radii.edwilliams16 wrote: ↑Mon Jun 06, 2022 6:59 pm It's problematic when the radius of curvature of the profile is smaller than the profile radius. I also moved the sweep path to the circle center. The result looks OK.
- radius of curvature of the profile
- profile radius.
if for profile you intend the circle as in my code I'm puzzled, please try to explain as this thing is interesting as "tube creation" is something I used, so it is interesting to see the critical points.
I could suppose that one of the profiles above is the "path" (as described in my code) but can't get the relations (sorry by my math is not at your level and I'm missing surely some passages).
Regards
Carlo D.
GitHub page: https://github.com/onekk/freecad-doc.
- In deep articles on FreeCAD.
- Learning how to model with scripting.
- Various other stuffs.
Blog: https://okkmkblog.wordpress.com/
- In deep articles on FreeCAD.
- Learning how to model with scripting.
- Various other stuffs.
Blog: https://okkmkblog.wordpress.com/
Re: sweep along any path
Thank you. But the software always crashes.