Skip to content

Instantly share code, notes, and snippets.

@ScruffyRules
Forked from mcy/sphere.java
Created July 17, 2014 16:58
Show Gist options
  • Save ScruffyRules/06649a263d14f31d950e to your computer and use it in GitHub Desktop.
Save ScruffyRules/06649a263d14f31d950e to your computer and use it in GitHub Desktop.
public static List<Location> sphere(Location l, double radius){
return sphere(l, radius, 64);
}
public static List<Location> sphere(Location l, double radius, int iterations){
List<Location> list = new ArrayList<>();
for(int i = 0; i < iterations; i++){
for(int j = 0; j < iterations; j++){
double theta = i * (2 * Math.PI / iterations);
double phi = j * (2 * Math.PI / iterations);
Vector v = new Vector(Math.sin(theta) * Math.cos(phi), Math.cos(theta), Math.sin(theta) * Math.sin(phi));
v.multiply(radius);
list.add(l.clone().add(v));
}
}
return list;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment