Prisms and Antiprisms

A prism is a 3D shape with two matching polygonal faces connected by straight edges.
To create these objects in the virtual world we can reuse our code for making polygons and simply connect the edges
to prism :n :r :h
; Generates an n-gonal prism of radius r and height h
make "s 2 * :r * sin( 180 / :n ) ; Side length
ru 90 fd :h / 2 rd 90 polygon :n :r
rd 90 fd :h ru 90 polygon :n :r
fd :r rt 90 + 180 / :n
pd ru 90 fd :h rd 90
repeat :n [ fd :s rd 90 fd :h ru 180 fd :h rd 90 rt 360 / :n ] pu
rt 90 - 180 / :n fd :r rt 180 rd 90 fd :h / 2 ru 90
; Generates an n-gonal prism of radius r and height h
make "s 2 * :r * sin( 180 / :n ) ; Side length
ru 90 fd :h / 2 rd 90 polygon :n :r
rd 90 fd :h ru 90 polygon :n :r
fd :r rt 90 + 180 / :n
pd ru 90 fd :h rd 90
repeat :n [ fd :s rd 90 fd :h ru 180 fd :h rd 90 rt 360 / :n ] pu
rt 90 - 180 / :n fd :r rt 180 rd 90 fd :h / 2 ru 90
An antiprism is like a prism, but its top and bottom faces are rotated and connected with triangles.
The following logo procedure defines antiprisms centered at the origin:
to antiprism :n :r :h
ru 90 fd :h / 2 rd 90 polygon :n :r
rd 90 fd :h ru 90 rt 180 / :n polygon :n :r pu
rt 90 fd :r rt 90
rt 90 / :n pd
for [ i 1 :n 1 ][
make "angle1 ( 360 * :i ) / :n
make "angle2 ( 360 * :i + 180 ) / :n
make "x1 :r * cos :angle1
make "x2 :r * cos :angle2
make "z1 :r * sin :angle1
make "z2 :r * sin :angle2
make "diag sqrt ( :h ^ 2 + ( :x2 - x1 ) ^ 2 + ( :z2 - :z1 ) ^ 2 ) ; Triangle side length
lookatxyz( :x1 ) ( :h / 2 ) ( :z1 ) fd :diag
lookatxyz( :x2 ) ( -:h / 2 ) ( :z2 ) fd :diag
]
end
Interestingly, the triangular faces of an antiprism form a shape known as a skew regular polygon. That is a polygon which is regular, but not confined to 2-dimensional space alone.
- dpietrobon's blog
- Login or register to post comments
- 68 reads