okay he's for n sides while retaining its mobius quality - I *will* stop

playing with this now!

----snip-----

STEP=4; // fine in most cases

SCALE=14; // of overall knot

// three SIDES will need the whole model rotating to sit flat on base

SIDES=3; // number of sides in the profile 3 to 16 (unless printed very

large 16 should be plenty for printing)

$fn=SIDES; // use to select number of faces in the path profile

// calculates position in path a=angle s=scale

function knotAng(a,s) =

[(sin(a)+(2*sin(2*a)))*s,

(cos(a)-(2*cos(2*a)))*s,

sin(3*a)*(s*1.5)];

// from wiki

// Find the unitary vector with direction v. Fails if v=[0,0,0].

function unit(v) = norm(v)>0 ? v/norm(v) : undef;

// Find the transpose of a rectangular matrix

function transpose(m) = // m is any rectangular matrix of objects

[ for(j=[0:len(m[0])-1]) [ for(i=[0:len(m)-1]) m[i][j] ] ];

// The identity matrix with dimension n

function identity(n) = [for(i=[0:n-1]) [for(j=[0:n-1]) i==j ? 1 : 0] ];

// computes the rotation with minimum angle that brings a to b

// the code fails if a and b are opposed to each other

function rotate_from_to(a,b) =

let( axis = unit(cross(a,b)) )

axis*axis >= 0.99 ?

transpose([unit(b), axis, cross(axis, unit(b))]) *

[unit(a), axis, cross(axis, unit(a))] :

identity(3);

for (a=[0:STEP:360]) {

v = knotAng(a,SCALE) - knotAng(a+STEP,SCALE);

v2 = knotAng(a+STEP,SCALE) - knotAng(a+STEP+STEP,SCALE);

hull() {

translate(knotAng(a,SCALE))

multmatrix(rotate_from_to([0,0,1],v))

rotate(a*(1+(1.0/SIDES))) // fudge

cylinder(r=SCALE/2,h=0.1,center=true);

translate(knotAng(a+STEP,SCALE))

multmatrix(rotate_from_to([0,0,1],v2))

rotate((a*(1+(1.0/SIDES)))+STEP) // fudge

cylinder(r=SCALE/2,h=0.1,center=true);

}

}

//base

translate([0,0,-1.35*(SCALE*1.5)]) cylinder(r=3*SCALE,h=2,$fn=128);

On 10/04/17 01:55, MichaelAtOz wrote:

> Nice.

> $fn needs to be multiple of 4.

> Shame, as $fn=3 looks great apart from the misalignment...

>

>

>

> -----

> Admin - PM me if you need anything, or if I've done something stupid...

>

> Unless specifically shown otherwise above, my contribution is in the Public Domain; to the extent possible under law, I have waived all copyright and related or neighbouring rights to this work. Obviously inclusion of works of previous authors is not included in the above.

>

> The TPP is no simple “trade agreement.” Fight it!

http://www.ourfairdeal.org/ time is running out!

> --

> View this message in context:

http://forum.openscad.org/simple-Celtic-knot-tp21141p21152.html> Sent from the OpenSCAD mailing list archive at Nabble.com.

>

> _______________________________________________

> OpenSCAD mailing list

>

[hidden email]
>

http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org_______________________________________________

OpenSCAD mailing list

[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org