[OpenSCAD] Twisted Torus

Zacariaz zacariaz at gmail.com
Sat Oct 6 19:30:08 EDT 2018


So I've finally put together a working module. It is by no means perfect, but
it'll do for my needs I think. In any case it's about the best I can achieve
at this point.

/*
r1: radius 1
r2: radius 2
ca: circle angle, i.e. 180 for a half circle and 360 for a full circle
seg: number of segments
*/
function flatten(l) = [ for (a = l) for (b = a) b ] ;

module twistedTorus( r1, r2, ca, seg )
{
    s2 = round(2*(r1+r2)*3.14/(2*r1*3.14)*seg);
    p = flatten(
    [
    for( ta = [0:360/s2:359] )
    [
        [
            -sin(ta)*r2,
            cos(ta)*r2,
            0
        ],
        for( i = [ta:360/seg:ca+ta] )
            [
                -sin(ta)*(cos(i)*r1+r2),
                cos(ta)*(cos(i)*r1+r2),
                sin(i)*r1
            ]
    ]
    
    ]);
    f1 =
    [
        for( i = [0:len(p)-1])
        [
            i,
            (i+1)%len(p),
            (i+seg/(360/ca)+2)%len(p),
        ]
    ];
    f2 = 
    [
        for( i = [0:len(p)-1])
        [
            (i+1)%len(p),
            (i+seg/(360/ca)+3)%len(p),
            (i+seg/(360/ca)+2)%len(p)
        ]
    ];
    polyhedron( points = p, faces = concat(f1,f2) );
}

twistedTorus(25.4/4, 25.4/2, 180, 60);



--
Sent from: http://forum.openscad.org/



More information about the Discuss mailing list