sweep along any path

About the development of the Part Design module/workbench. PLEASE DO NOT POST HELP REQUESTS HERE!
wwshunan
Posts: 5
Joined: Sun Jun 05, 2022 4:19 pm

sweep along any path

Post by wwshunan »

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.
chrisb
Veteran
Posts: 43448
Joined: Tue Mar 17, 2015 9:14 am

Re: sweep along any path

Post by chrisb »

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.
A Sketcher Lecture with in-depth information is available in English, auf Deutsch, en français, en español.
wwshunan
Posts: 5
Joined: Sun Jun 05, 2022 4:19 pm

Re: sweep along any path

Post by wwshunan »

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.
Attachments
v_pole.txt
(22.27 KiB) Downloaded 12 times
sweep.FCStd
(66.54 KiB) Downloaded 11 times
chrisb
Veteran
Posts: 43448
Joined: Tue Mar 17, 2015 9:14 am

Re: sweep along any path

Post by chrisb »

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:
SnipScreenshot-ca7a21.png
SnipScreenshot-ca7a21.png (6.17 KiB) Viewed 631 times
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.
User avatar
onekk
Veteran
Posts: 2749
Joined: Sat Jan 17, 2015 7:48 am
Contact:

Re: sweep along any path

Post by onekk »

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)
But the result is messed up.

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:
20220606-sweep.png
20220606-sweep.png (8.3 KiB) Viewed 610 times

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")
Hope it helps

Regards

Carlo D.
My English and Italian Scripting Guide https://github.com/onekk/freecad-doc.
My Blog: https://onekk-maker.blogspot.com/

To help development see on GitHub Page

For enquiry about customized FC Scripting job PM me.
wwshunan
Posts: 5
Joined: Sun Jun 05, 2022 4:19 pm

Re: sweep along any path

Post by wwshunan »

Thank you very much. However freeCAD eated up 8G memory of my computer when I executed the script and the software crashed.
User avatar
onekk
Veteran
Posts: 2749
Joined: Sat Jan 17, 2015 7:48 am
Contact:

Re: sweep along any path

Post by onekk »

wwshunan wrote: Mon Jun 06, 2022 3:24 pm Thank you very much. However freeCAD eated up 8G memory of my computer when I executed the script and the software crashed.
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.
My English and Italian Scripting Guide https://github.com/onekk/freecad-doc.
My Blog: https://onekk-maker.blogspot.com/

To help development see on GitHub Page

For enquiry about customized FC Scripting job PM me.
edwilliams16
Veteran
Posts: 1352
Joined: Thu Sep 24, 2020 10:31 pm
Location: Hawaii
Contact:

Re: sweep along any path

Post by edwilliams16 »

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.
Screen Shot 2022-06-06 at 8.55.24 AM.png
Screen Shot 2022-06-06 at 8.55.24 AM.png (33.44 KiB) Viewed 487 times

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)

User avatar
onekk
Veteran
Posts: 2749
Joined: Sat Jan 17, 2015 7:48 am
Contact:

Re: sweep along any path

Post by onekk »

edwilliams16 wrote: Mon Jun 06, 2022 6:59 pm I down-sampled @onekk's script and made the circle smaller.
down sampled my script or the points?

:-D
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.
Sorry I'm confused with all these radii.

- 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). :oops:


Regards

Carlo D.
My English and Italian Scripting Guide https://github.com/onekk/freecad-doc.
My Blog: https://onekk-maker.blogspot.com/

To help development see on GitHub Page

For enquiry about customized FC Scripting job PM me.
wwshunan
Posts: 5
Joined: Sun Jun 05, 2022 4:19 pm

Re: sweep along any path

Post by wwshunan »

Thank you. But the software always crashes.
Post Reply