Created
August 7, 2024 02:39
-
-
Save callistabee/75abfba4835561b0c6a861acb59ea036 to your computer and use it in GitHub Desktop.
openscad module for making an upside-down paraboloid
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// make an upside-down paraboloid of given height, base radius, and number of steps | |
module paraboloid(height, radius, n_z=6, n_r=6) { | |
// interpolate z-axis using n_z | |
zs = [ | |
for (i=[0:n_z-1]) | |
i*height/(n_z-1) | |
]; | |
// compute radii for each interpolated layer | |
rs = [ | |
for (i=[0:n_z-1]) | |
sqrt(height - zs[i])/sqrt(height) * radius | |
]; | |
// enumerate vertices (clockwise) | |
vertices = [each | |
for (i=[0:n_z-1]) [each | |
for (j=[0:n_r-1]) [ | |
let (theta=j*360/n_r) ( | |
[ rs[i]*cos(theta) | |
, rs[i]*sin(theta) | |
, zs[i] | |
] | |
) | |
] | |
] | |
]; | |
// seal the bottom | |
bottom_face = [0,1,2,3,4,5]; | |
// enumerate side faces | |
side_faces = [ | |
each for (i=[0:n_z-2]) [ | |
each for (j=[0:n_r-1]) [ | |
let | |
( cur_start = i*n_r | |
, next_start = (i+1)*n_r | |
) | |
( i == n_z-2 ? // last layer, make triangles | |
[ cur_start + (j + 1)%n_r | |
, cur_start + j | |
, next_start + j | |
] | |
: // otherwise make quads | |
[ cur_start + (j + 1)%n_r | |
, cur_start + j | |
, next_start + j | |
, next_start + (j + 1)%n_r | |
] | |
) | |
] | |
] | |
]; | |
faces = concat([bottom_face], side_faces); | |
polyhedron(vertices, faces); | |
} | |
paraboloid(12, 10, n_r=6, n_z=128); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
result of running the code above:
