« OpenSCAD : LOL-SCAD » : différence entre les versions

De Vanlindt Marc
Aller à la navigation Aller à la recherche
Ligne 30 : Ligne 30 :


==== Code de la fonction ====
==== Code de la fonction ====
<syntaxhighlight lang="openscad" line="1">
<syntaxhighlight lang="openscad" line="1" start="1">
function teardrop(d,a,fn)=let (
function teardrop(d,a,fn)=let (
   d=d==undef?10:d,
   d=d==undef?10:d,
Ligne 44 : Ligne 44 :


==== Exemple ====
==== Exemple ====
<syntaxhighlight lang="openscad" line="1">
<syntaxhighlight lang="openscad" line="1" start="1">
teardrop(d=5,a=45,fn=32);
teardrop(d=5,a=45,fn=32);
tear= teardrop(d=3,a=20,fn=32);
tear= teardrop(d=3,a=20,fn=32);

Version du 1 octobre 2025 à 17:26

Le but de LOLScad est de permettre l'utilisation de formes en tant que variable afin de permettre de nouvelles formes et transformations.

Cela change en profondeur la manière d'utiliser OpenSCAD. Par exemple, pour faire un carré :

Avant

square([3,4],center=true);

Après

moncarre = square([3,4],center=true);

2D(moncarre);

La différence ?

Si vous réalisez un echo de la variable moncarre, la console affichera : [[-1.5,-2],[-1.5,2],[1.5,2],[-1.5,2]]


Objets 2D

Tous les objets (y compris ceux d'origine d'OpenSCAD) peuvent être utilisés à la fois en tant que variable qu'en tant

Teardrop

Paramètres

  • d : diamètre
  • a : angle
  • fn : qualité

Code de la fonction

function teardrop(d,a,fn)=let (
  d=d==undef?10:d,
  a=a==undef?30:a,
  h=d*tan(90-a),
  fn=fn==undef?16:fn,
  courbe= [for(i=[0:fn]) [sin(90-a+(360-(90-a)*2)/fn*i)*d/2,cos(90-a+(360-(90-a)*2)/fn*i)*d/2]],
  aa=concat(courbe,[[0,(cos(90-a)*d/2)+h*sin(90-a)/2]],[[sin(90-a)*d/2,cos(90-a)*d/2]])
)
aa;
OpenSCAD - Teardrop

Exemple

teardrop(d=5,a=45,fn=32);
tear= teardrop(d=3,a=20,fn=32);
tear2= teardrop(d=3,a=10,fn=3);
translate([5,0,0]) 2D(tear);
translate([9,0,0]) 2D(tear2);
echo(tear);