Skip to content

Instantly share code, notes, and snippets.

@thehans
Last active July 28, 2017 18:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thehans/e45693b0bdf6077e92a225c2af67397a to your computer and use it in GitHub Desktop.
Save thehans/e45693b0bdf6077e92a225c2af67397a to your computer and use it in GitHub Desktop.
Roughly simulating gravitational effects in openscad, by request
use <functional.scad>; // from https://github.com/thehans/FunctionalOpenSCAD
black_hole_center = [5,5,5];
black_hole_mass = 45*$t;
wallsize = [10,10];
stepsize = [0.5,0.5];
grid = gridPoints([wallsize.x,0.1], stepsize);
wall = linear_extrude(height=10, poly=grid, slices=wallsize.y/stepsize.y);
warpedWall = warpPoints(wall, black_hole_center, black_hole_mass);
//poly2d(grid);
poly3d(wall);
poly3d(warpedWall);
color([0,0,0]) translate(black_hole_center) sphere(0.1);
function gridPoints(size, stepsize, zoffset) =
let(
xcount = ceil(size.x/stepsize.x)
)
[for(j = [0:1], i = [0:1:xcount]) [j ? stepsize.x*xcount - i*stepsize.x : i*stepsize.x, j*size.y] ];
function warpPoints(poly, center, mass) =
let(
points = get_points(poly),
newpoints = [for (point = points)
let(r = norm(point-center), G = min(1,mass/(r*r)) )
point+(center-point)*G
]
)
[newpoints, poly[1]];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment