VoxelPolygonTest.frink

Download or view VoxelPolygonTest.frink in plain text format


/** This program tests the extrusion of a polygon for 3D printing. */

polygon = newJava["frink.graphics.Point2DFloatList"]

sides = 7
sideAngle = circle/sides
angle = 90 deg  // Point at top

outerRadius = .5 in

res = 254/in

for i=0 to sides-1
{
   x = outerRadius cos[angle] res
   y = outerRadius sin[angle] res
   polygon.addPoint[x,y]
   angle = angle + sideAngle
}

c = polygon.getCentroidAndArea[]
println["Area is " + format[c.area / (res^2), "in^2", 4]]
println["Centroid is [" + format[c.centroid.x/res, "in", 5] + ", " + format[c.centroid.y/res, "in", 5] + "]"]

bb = polygon.getBoundingBox[]
println["Bounding box is: " + bb.toString[]]

v = callJava["frink.graphics.VoxelArray", "extrudeZ", [polygon, round[0 in res], round[1 in res]]]

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

filename = "VoxelPolygonTest.obj"
print["Writing $filename..."]
w = new Writer[filename]
w.println[v.toObjFormat["rotate", 1/(res mm)]]
w.close[]
println["done."]


Download or view VoxelPolygonTest.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 20217 days, 23 hours, 42 minutes ago.