Skip to content

Instantly share code, notes, and snippets.

@player1537
Created January 20, 2017 14:56
Show Gist options
  • Save player1537/2814167ad856a9b2411586258d920822 to your computer and use it in GitHub Desktop.
Save player1537/2814167ad856a9b2411586258d920822 to your computer and use it in GitHub Desktop.

Probabilistic SCAD

This idea would build on the idea of OpenSCAD which is a "Programmer's Solid 3D CAD Modeller." In short, you could write code to generate 3D models that could be 3D printed, like:

// Resolution
$fn=50;

//Move the hole thing up
translate (v=[0,0,12]) {

  difference() {
    difference() {
      // Outer Ball
      sphere(r=10, $fn=50); 
      translate(v=[0,0,2]) {
	//Inner Ball
	sphere(r=8, $fn=50); 
      }
    }
    translate(v=[0,0,5]) {
      // Cutting cube
      cube(size = [20,20,10], center = true);
    }
  }
  // Something to sit on
  translate(v=[0,0,-10]) {
    cylinder (h=4, r1=5, r2=6, center = true);	
  }
}

Difference between existing project

The key difference between OpenSCAD and this project is that this would use a Monte Carlo method of generating the models instead of computing each vertex exactly. With OpenSCAD, models are generated by exactly computing the intersection of the edges and vertices. So, if you have the intersection of two cylinders, then it will take each edge of the cylinders and check if they intersect with any of the other edges. Obviously, this takes a lot of time as models get more complex.

With this project, we would only keep track of the simple polygons and whether we take the binary AND, OR, or XOR with other polygons. For example, if we had the difference between two cubes, we would generate a random point, check if it is within the first cube and if it is, then we check that it's not in the second cube, so we implictly get the difference between them.

Timeline

Because we want to have a minimal viable product in the first few weeks, then we can start with hard coding some of the models and using very simple operations, then we can expand it to work with OpenSCAD source code (like the one above).

The most simple thing we could do is to split each model into triangular pyramids (which are very easy to check whether a point is inside it or not) and implement the basic AND, OR, and XOR operations.

One of the harder aspects is turning the cloud of points into an actual model, but it's also not an impossible task. For example, this Blender script can turn a cloud of points into a flat surface or into a volumetric model. We could either learn from this code and use that to write our own, or see if we can incorporate the code into the early versions of the project.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment