impossibleSphere.frink

Download or view impossibleSphere.frink in plain text format


// This draws an "impossible" sphere inside a box for 3-D printing.
// The output is a Wavefront .obj format.

s = 254/2
radius = 18   // Radius of the edges of the cube
s2 = s - radius
v = callJava["frink.graphics.VoxelArray", "makeSphere", [s]]

// Make the edges of the cube as cylinders with hemispherical endcaps
// Bottom square
line[v, -s2, -s2, -s2,  s2, -s2, -s2, radius]
line[v, -s2, -s2, -s2, -s2,  s2, -s2, radius]
line[v,  s2, -s2, -s2,  s2,  s2, -s2, radius]
line[v, -s2,  s2, -s2,  s2,  s2, -s2, radius]

// Top square
line[v, -s2, -s2, s2,  s2, -s2, s2, radius]
line[v, -s2, -s2, s2, -s2,  s2, s2, radius]
line[v,  s2, -s2, s2,  s2,  s2, s2, radius]
line[v, -s2,  s2, s2,  s2,  s2, s2, radius]

// Vertical bars
line[v, -s2, -s2, -s2,  -s2, -s2, s2, radius]
line[v,  s2, -s2, -s2,   s2, -s2, s2, radius]
line[v, -s2,  s2, -s2,  -s2,  s2, s2, radius]
line[v,  s2,  s2, -s2,   s2,  s2, s2, radius]


v.projectX[undef].show["X"]
v.projectY[undef].show["Y"]
v.projectZ[undef].show["Z"]   

filename = "impossibleSphere.obj"
print["Writing $filename..."]
w = new Writer[filename]
w.println[v.toObjFormat["test"]]
w.close[]
println["done."]

/** This draws a "line" (a capped cylinder) into the specified VoxelArray */
line[v, x1, y1, z1, x2, y2, z2, radius] :=
{
   v.drawCappedCylinder[x1, y1, z1, x2, y2, z2, radius]
}


Download or view impossibleSphere.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 was born 19945 days, 7 hours, 17 minutes ago.