

// 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=2*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);
ã
Created: NaN
Last updated: 16-02-2026 [16:02]
For attribution, please cite this page as:
Charters, T., "Trefoil knot -- Example of a 3D curve": https://nexp.pt/3knot.html (16-02-2026 [16:02])
(cc-by-sa) Tiago Charters - tiagocharters@nexp.pt