Trefoil knot in openscad with python
Here is the PythonSCAD variant. It does not need external Programs/Libraries
https://www.thingiverse.com/thing:6065385/
from math import *
fn=20
def knot(t):
return [ sin(t)+2.0sin(2.0t), cos(t)-2.0cos(2.0t),sin(3.0t)]
n=150
pts=[]
for i in range(n):
pts.append(knot(23.1415926*i/n))
path_extrude(square(0.5),pts,twist=-120,closed=True).output()
Greets from Austria
On Sun, Oct 20, 2024 at 3:46 PM Sanjeev Prabhakar via Discuss <
discuss@lists.openscad.org> wrote:
Trefoil knot in openscad with python
https://youtu.be/aRY3jPGwudU?si=ywFVHaYWSELAbPo6
OpenSCAD mailing list
To unsubscribe send an email to discuss-leave@lists.openscad.org
Not hard in pure OpenSCAD. This is an example from NopSCADlib's sweep test.
knot = [ for(i=[0:.2:359])
[ (19cos(3i) + 40)cos(2i),
(19cos(3i) + 40)sin(2i),
19sin(3i) ] ];
color("red") sweep(knot, circle_points(5), loop = true);
[image: image.png]
On Sun, 20 Oct 2024 at 15:28, Guenther Sohler via Discuss <
discuss@lists.openscad.org> wrote:
Here is the PythonSCAD variant. It does not need external
Programs/Libraries
https://www.thingiverse.com/thing:6065385/
from math import *
fn=20
def knot(t):
return [ sin(t)+2.0sin(2.0t), cos(t)-2.0cos(2.0t),sin(3.0t)]
n=150
pts=[]
for i in range(n):
pts.append(knot(23.1415926*i/n))
path_extrude(square(0.5),pts,twist=-120,closed=True).output()
Greets from Austria
On Sun, Oct 20, 2024 at 3:46 PM Sanjeev Prabhakar via Discuss <
discuss@lists.openscad.org> wrote:
Trefoil knot in openscad with python
https://youtu.be/aRY3jPGwudU?si=ywFVHaYWSELAbPo6
OpenSCAD mailing list
To unsubscribe send an email to discuss-leave@lists.openscad.org
OpenSCAD mailing list
To unsubscribe send an email to discuss-leave@lists.openscad.org
On Sunday, October 20, 2024 at 10:28:44 AM EDT, Guenther Sohler via Discuss discuss@lists.openscad.org wrote:
Here is the PythonSCAD variant. It does not need external Programs/Libraries
https://www.thingiverse.com/thing:6065385/
from math import *
fn=20
def knot(t):
return [ sin(t)+2.0sin(2.0t), cos(t)-2.0cos(2.0t),sin(3.0t)]
n=150
pts=[]
for i in range(n):
pts.append(knot(23.1415926*i/n))
path_extrude(square(0.5),pts,twist=-120,closed=True).output()
When I tried that in the new OpenPythonSCAD I get:
ERROR: Traceback (most recent call last):
File "<string>", line 9, in <module>
NameError: name 'path_extrude' is not defined
and had to add (of course)
from openscad import *
Once that was added, it worked as expected:
William
Great
You can try this to make a basket like structure:
n=10
path=[ [10*(sin(d2r(t))+nsin(nd2r(t))),
10*(cos(d2r(t))-ncos(nd2r(t))),
-30*cos((n+1)*d2r(t))
] for t in range(0,360)]
change the value of 'n' from 5 to 10 or more
On Sun, 20 Oct 2024 at 20:43, William F. Adams via Discuss <
discuss@lists.openscad.org> wrote:
On Sunday, October 20, 2024 at 10:28:44 AM EDT, Guenther Sohler via
Discuss discuss@lists.openscad.org wrote:
Here is the PythonSCAD variant. It does not need external
Programs/Libraries
https://www.thingiverse.com/thing:6065385/
from math import *
fn=20
def knot(t):
return [ sin(t)+2.0sin(2.0t), cos(t)-2.0cos(2.0t),sin(3.0t)]
n=150
pts=[]
for i in range(n):
pts.append(knot(23.1415926*i/n))
path_extrude(square(0.5),pts,twist=-120,closed=True).output()
When I tried that in the new OpenPythonSCAD I get:
ERROR: Traceback (most recent call last):
File "<string>", line 9, in <module>
NameError: name 'path_extrude' is not defined
and had to add (of course)
from openscad import *
Once that was added, it worked as expected:
William
OpenSCAD mailing list
To unsubscribe send an email to discuss-leave@lists.openscad.org
Here is a self-contained OpenSCAD only version:
function flatten(vec) = [for (v=vec) for(e=v) e];
function rotQ(q, a, n) = Q_mult(flatten([cos(a/2),n*sin(a/2)]),q);
function Q_mult(q,p) =
[(q[0]*p[0]-q[1]*p[1]-q[2]*p[2]-q[3]*p[3]),(q[1]*p[0]+q[0]*p[1]+q[2]*p[3]-q[3]*p[2]),(q[2]*p[0]+q[0]*p[2]-q[1]*p[3]+q[3]*p[1]),(q[3]*p[0]+q[0]*p[3]+q[1]*p[2]-q[2]*p[1])];
function poly_addZ(list, z) = [for (v=list) [v[0], v[1], z]];
function poly_translate(list, d) = [for (v=list) v+d];
function poly_rotQ(list, q) = [for (v=list)
Q_im(Q_mult(q,Q_mult([0,v.x,v.y,v.z],Q_conj(q))))];
function Q_im(q) = [q[1], q[2], q[3]];
function rot2d(x, a) = [cos(a)*x[0]+sin(a)*x[1], -sin(a)*x[0]+cos(a)*x[1]];
function poly_rot2d(list, a) = [for (v=list) rot2d(v, a)];
function Q_conj(q) = [q[0], -q[1], -q[2], -q[3]];
function poly_loft_faces (N_z, N_x, closed=false) = flatten([
(closed ? ([for (i=[0:N_x-1]) [(N_z-1)*N_x+i, (N_z-1)*N_x+(i+1)%N_x,
i],
for (i=[0:N_x-1]) [(i+1)%N_x, i, (N_z-1)N_x+(i+1)%N_x]])
: concat([[for (i=[0:N_x-1]) N_x-1-i]], [[for (i=[0:N_x-1])
(N_z-1)N_x+i]])), // caps
for (i=[0:N_z-2],j=[0:N_x-1]) [[(i+1)N_x+j, iN_x+j,
iN_x+((j+1)%N_x)],[iN_x+((j+1)%N_x), (i+1)*N_x+((j+1)%N_x),
(i+1)*N_x+j]]]);
module extrude (path, cr, closed=false, twist=0) {
p = flatten([path, [2*path[len(path)-1]-path[len(path)-2]]]);
pts = flatten([
for (i=1, d=p[1]-p[0], u=cross([0,0,1], d), un=norm(u), dn=norm(d),
a=asin(un/dn),
q=un>0?rotQ([1,0,0,0],a,u/un) : [1,0,0,0], n=d/dn,
c=poly_addZ(cr,0);
i<len(p);
d=p[i]-path[i-1], u=cross(n, d), un=norm(u), dn=norm(d),
a=asin(un/dn),
n=d/dn,q=un>0?rotQ(q,a,u/un):q, i=i+1)
poly_translate(poly_rotQ((twist!=0)?poly_addZ(poly_rot2d(cr,i*twist/(len(p)-1)),0):c,
q), p[i-1])
]);
fcs = poly_loft_faces(len(path), len(cr), closed);
polyhedron(pts, fcs, convexity=8);
}
myPath = [ for(t = [0:(360/360):359]) [ // trefoil knot
5*(.41cos(t) - .18sin(t) - .83cos(2t) - .83sin(2t) - .11cos(3t)
function rpoly_circle(r=1,pts=24) = [for (i=[0:pts-1]) r*[cos(i360/pts),
sin(-i360/pts)]];
extrude(myPath, rpoly_circle(1.8, 60), closed=true, twist=-78);
On Sun, Oct 20, 2024 at 11:57 AM Sanjeev Prabhakar via Discuss <
discuss@lists.openscad.org> wrote:
Great
You can try this to make a basket like structure:
n=10
path=[ [10*(sin(d2r(t))+nsin(nd2r(t))),
10*(cos(d2r(t))-ncos(nd2r(t))),
-30*cos((n+1)*d2r(t))
] for t in range(0,360)]
change the value of 'n' from 5 to 10 or more
On Sun, 20 Oct 2024 at 20:43, William F. Adams via Discuss <
discuss@lists.openscad.org> wrote:
On Sunday, October 20, 2024 at 10:28:44 AM EDT, Guenther Sohler via
Discuss discuss@lists.openscad.org wrote:
Here is the PythonSCAD variant. It does not need external
Programs/Libraries
https://www.thingiverse.com/thing:6065385/
from math import *
fn=20
def knot(t):
return [ sin(t)+2.0sin(2.0t), cos(t)-2.0cos(2.0t),sin(3.0t)]
n=150
pts=[]
for i in range(n):
pts.append(knot(23.1415926*i/n))
path_extrude(square(0.5),pts,twist=-120,closed=True).output()
When I tried that in the new OpenPythonSCAD I get:
ERROR: Traceback (most recent call last):
File "<string>", line 9, in <module>
NameError: name 'path_extrude' is not defined
and had to add (of course)
from openscad import *
Once that was added, it worked as expected:
William
OpenSCAD mailing list
To unsubscribe send an email to discuss-leave@lists.openscad.org
OpenSCAD mailing list
To unsubscribe send an email to discuss-leave@lists.openscad.org
Easy geometric explanation on cinquefoil torus knots
https://youtu.be/tRWPeoyQhWs?si=Nx63gUabK-AUWELE
On Sun, 20 Oct, 2024, 7:15 pm Sanjeev Prabhakar, sprabhakar2006@gmail.com
wrote: