Skip to content

Instantly share code, notes, and snippets.

@ecto
Created November 23, 2013 23:35
Show Gist options
  • Select an option

  • Save ecto/7621390 to your computer and use it in GitHub Desktop.

Select an option

Save ecto/7621390 to your computer and use it in GitHub Desktop.

Revisions

  1. ecto created this gist Nov 23, 2013.
    9 changes: 9 additions & 0 deletions gravity.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,9 @@
    var G = 100;
    var vertex;

    for (var i = 0; i < plane.geometry.vertices.length; i++) {
    vertex = plane.geometry.vertices[i];
    var distance = Math.sqrt(Math.pow(vertex.x - sphere.position.x, 2) + Math.pow(vertex.y - -sphere.position.z, 2));
    var f = -(G * sphere.mass) / Math.pow(distance, 2);
    vertex.z = f;
    }