/** This renders an egg with the Moon's craters for 3-D printing. It requires data files from NASA: https://svs.gsfc.nasa.gov/4720 Specifically the 1440x720 16-bit unsigned int TIFF displacement file renamed here to "moonhalfmeter.tif". */ use Plot3D.frink res = 254/in // Resolution of the model in voxels/inch (0.1 mm) img = new image["file:moonhalfmeter.tif"] img.show[] p = new Plot3D[] p.setBounds[-5, 5, -5, 5, -10, 0.1] p.setDoublings[10] p.setResolution[res] v = p.plot["(x^2 + y^2 + z^2)^2 <= -6 (1.5 z^3 + (1.5 - 1.1) z (y^2 + x^2))"] c = v.centerOfMass[] println["Center of mass : " + c.toString[]] // This calculates a geometric center of set points as opposed to center of mass min = v.getMinimumSetPoints[] max = v.getMaximumSetPoints[] cx = (min.x + max.x) div 2 cy = (min.y + max.y) div 2 cz = (min.z + max.z) div 2 println["Minimum set points: " + min.toString[]] println["Maximum set points: " + max.toString[]] println["cx=$cx, cy=$cy, cz=$cz"] // Wrap the moon depth map around the egg // See the methods on VoxelArray here: // https://frinklang.org/3d/ pixelTool = newJava["frink.graphics.VoxelArray", [0,2,0,2,0,2,true]] emboss = v.sphericalEmboss[img, cx, cy, cz, 180 deg, 360 deg, 0 deg, 180 deg, 0, 255, 0 mm res, 0 mm res, 9.6 mm res, 0 mm res, pixelTool, 0, 0, 0] v.remove[emboss] p.show[v] p.writeObj[v,"embossEggMoon"]