Closed RemDelaporteMathurin closed 2 years ago
You need to have the normal of your circle aligned with the tangent of your spline at the start :
pts = [
(1, 1, 1),
(1, 2, 2),
(1, 3, 3),
]
p = cq.Workplane("XY").spline(pts, includeCurrent=True)
dire = p.val().tangentAt(0)
plane = cq.Plane((0,0,0), normal=dire)
s = cq.Workplane(plane).circle(1).sweep(p)
Thanks for the hint!
Note that this is true for any curve (even straight lines) not only splines
Noted!
I tried to apply it to a more complex curve composed of a straight bit and a semi-circle but I have some weird results. Is it related?
import cadquery as cq
from cadquery import exporters
import numpy as np
target_radius = 50
L = 200
inner_radius = 6
pts = []
# line points
for y_loc in np.linspace(0, L, num=10):
pts.append((0, 0, y_loc))
# curve points
for theta in np.linspace(0.5 * np.pi, 0 * np.pi, num=50):
pts.append(
(
0,
target_radius + target_radius * np.cos(theta),
L + target_radius * np.sin(theta),
)
)
p = cq.Workplane("ZX").spline(pts[1:], includeCurrent=True)
dire = p.val().tangentAt(0)
plane = cq.Plane((0, 0, 0), normal=dire)
s = cq.Workplane(plane).circle(inner_radius).sweep(p)
exporters.export(s, "out.stl")
@RemDelaporteMathurin If what you're displaying is the exported STL, you may need to adjust your tolerance settings on the export call. Does it display fine in CQ-editor?
@RemDelaporteMathurin If what you're displaying is the exported STL, you may need to adjust your tolerance settings on the export call. Does it display fine in CQ-editor?
Yes this is the STL. I'll play with the tolerances then! Thanks! I didn't use the CQ-editor I'm afraid
You could export a STEP and use an online viewer for a double check too.
Based on #296 , I would like to have the extrusion of the circle in the normal direction only (the idea is to make a classic tube from a set of points).
Unfortunately, this code produces a distorded tube:
Thanks for the help!