Using Functions in OpenSCAD

Type: Mini-lesson

Theme: Engineering

Grades: 9, 10

Learning Target: Students will incorporate functions into OpenSCAD engineering code.

id
  1. Write a function in Desmos graphing calculator, such as y=cos(x).
  2. Demonstrate how to incorporate the function into a loop for contructing a block.
  3. Have students repeat the process and share their output in the class chat.

Example 1

for (x= [-50:.1:50]){
y=20*cos(18*x);
translate([x,y,0])cube([1,1,10]);
}

Example 2

a=20;
b=15;
c=5;
k=10;
d=0.1;
for (x= [-30:d:30]){
y = a*cos(b*x)+c;
translate([x,y,0])color("blue")cube([1,1,10]);
}
for (x= [-30:d:30]){
y = a*cos(b*(x+k))-c;
translate([x,y,0])color("yellow")cube([1,1,10]);
}
for (x= [-30:d:30]){
y = a*cos(b*x)-c;
translate([x,y,0])color("red")cube([1,1,10]);
}
for (x= [-30:d:30]){
y = a*cos(b*(x+k))+c;
translate([x,y,0])color("green")cube([1,1,10]);
}
  • I can model with mathematics.
  • Structure and Function
Updated on
2021-03-05 16:34:16
user_id
David Zelenka
No