OpenSCAD

... the Programmers Solid 3D CAD Modeller

Some .scad files for Openscad.

Refs.:

Trefoil knot — Example of a 3D curve

// Author: Tiago Charters de Azevedo
// Maintainer: Tiago Charters de Azevedo
// URL: http://diale.org/openscad.html
// Version: 1

// Copyright (c) - 2014 Tiago Charters de Azevedo

// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 3, or (at your option)
// any later version.

// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor,
// Boston, MA 02110-1301, USA.

// Commentary:

// Usage:  see below.

// Returns the i-the  N linearly spaced elements between XMIN and XMAX.
// The endpoints are always included in the range.
function linspace(xmin,xmax,n,i)=xmin+i*(xmax-xmin)/n;

// Converts from rads to degs.
function deg(x)=180*x/3.141592653589793;

// Point coordinates.

// Examples: Trefoil knot
function coordinates(t) = 10*[(2+cos(3*deg(t)))*cos(2*deg(t)),
    (2+cos(3*deg(t)))*sin(2*deg(t)),
    -sin(3*deg(t))];
function varradius(t) = 5;


// Main module:
// tmin = inicial parameter value
// tmax = end parameter value
// n = number of segments (sphere used)


module curve(tmin=0,tmax=3.14,n=20){
    for (i=[0:n-1]){
        hull(){
            translate(coordinates(linspace(tmin,tmax,n,i))){
                sphere(r=varradius(linspace(tmin,tmax,n,i)));}
            translate(coordinates(linspace(tmin,tmax,n,i+1))){
                sphere(r=varradius(linspace(tmin,tmax,n,i+1)));}}}}



//--------------------------------------------------------------------------------

$fn = 10;
curve(n=100);

Exponential snail

// Exponential horn/snail.
// Author: Tiago Charters de Azevedo
// Maintainer: Tiago Charters de Azevedo
// URL: http://diale.org/openscad.html
// Version: 1

// Copyright (c) - 2014 Tiago Charters de Azevedo

// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 3, or (at your option)
// any later version.

// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor,
// Boston, MA 02110-1301, USA.

// Commentary:

// Returns the i-the  N linearly spaced elements between XMIN and XMAX.
// The endpoints are always included in the range.
function linspace(xmin,xmax,n,i)=xmin+i*(xmax-xmin)/n;

// Converts from rads to degs.
function deg(x)=180*x/3.1415926;

// Outer amplitude factor - decaying exponential for lambda > 0
// and radius > 0.
function amplitude(t,radius,lambda,) = radius*exp(-lambda*t);

// Outer amplitude factor - decaying exponential for slambda > 0
// and radius > 0.
function samplitude(t,sradius,slambda) = sradius*exp(-slambda*t);

// Point coordinates.
function coordinates(t) = [cos(deg(t)), sin(deg(t))];

// Snail module - uses cylinders:
// Usage: snail(0,6,30,1,10,.3,5,.4);
// tmin = inicial parameter value
// tmax = end parameter value
// n = number of segments (cylinders used)
// radius = outer radius
// lambda = decaying constant
// sradius = inner radius
// lambda = decaying constant surface

module snail(tmin,tmax,n,r,radius,lambda,sradius,slambda){
        for (i=[0:n-1]){
                hull(){
                    translate(amplitude(linspace(tmin,tmax,n,i),radius,lambda)*coordinates(linspace(tmin,tmax,n,i)),0){
                        rotate([0,90,deg(linspace(tmin,tmax,n,i))+90]){
                            cylinder(h=.1,r=samplitude(linspace(tmin,tmax,n,i),sradius,slambda));}}
                    translate(amplitude(linspace(tmin,tmax,n,i+1),radius,lambda)*coordinates(linspace(tmin,tmax,n,i+1)),0){
                        rotate([0,90,deg(linspace(tmin,tmax,n,i+1))+90]){
                            cylinder(h=.1,r=samplitude(linspace(tmin,tmax,n,i+1),sradius,slambda));}}}}}

// Snail module - uses spheres:
// Usage: snailsphere(0,6,30,1,10,.3,5,.4);
module snailsphere(tmin,tmax,n,r,radius,lambda,sradius,slambda){
        for (i=[0:n-1]){
                hull(){
                    translate(amplitude(linspace(tmin,tmax,n,i),radius,lambda)*coordinates(linspace(tmin,tmax,n,i)),0){
                        sphere(r=samplitude(linspace(tmin,tmax,n,i),sradius,slambda));}
                    translate(amplitude(linspace(tmin,tmax,n,i+1),radius,lambda)*coordinates(linspace(tmin,tmax,n,i+1)),0){
                        sphere(r=samplitude(linspace(tmin,tmax,n,i+1),sradius,slambda));}}}}


//--------------------------------------------------------------------------------

//$fn = 30;
snailsphere(0,6,50,1,10,.3,5,.6);


ãç

Palavras chave/keywords: cad, openscad, examples

Criado/Created: NaN

Última actualização/Last updated: 04-10-2021 [18:00]


Voltar à página inicial.


GNU/Emacs Creative Commons License

(c) Tiago Charters de Azevedo