Download or view tetrahedron.frink in plain text format
use geometry.frink
// Return a polygon object representing the specified equilateral triangle.
// THINK ABOUT: Would this be better as a GeneralPath of 4 disconnected
// polygons?
makeEquilateralTriangle[cx, cy, sideLength, rotation] :=
{
p = new polygon
halfL = 1/2 sideLength
h = halfL sqrt[3]
halfH = 1/2 h
x1 = cx
y1 = cy - halfH
[x2, y2] = rotateAroundPoint[x1,y1,cx,cy,rotation]
p.addPoint[x2, y2]
x1 = cx - halfL
y1 = cy + halfH
[x2, y2] = rotateAroundPoint[x1,y1,cx,cy,rotation]
p.addPoint[x2, y2]
x1 = cx + halfL
[x2, y2] = rotateAroundPoint[x1,y1,cx,cy,rotation]
p.addPoint[x2, y2]
return p
}
// Draw the specified tetrahedron into the graphics object.
makeTetrahedron[g is graphics, cx, cy, sideLength] :=
{
hl = sideLength / 2
ho = hl sqrt[3]
g.add[makeEquilateralTriangle[cx, cy, sideLength, 0 deg]]
g.add[makeEquilateralTriangle[cx, cy + ho, sideLength, 180 deg]]
g.add[makeEquilateralTriangle[cx + hl, cy + ho, sideLength, 0 deg]]
g.add[makeEquilateralTriangle[cx - hl, cy + ho, sideLength, 0 deg]]
}
g = new graphics
makeTetrahedron[g, 0, 0, 1]
g.show[]
Download or view tetrahedron.frink in plain text format
This is a program written in the programming language Frink.
For more information, view the Frink
Documentation or see More Sample Frink Programs.
Alan Eliasen, eliasen@mindspring.com