Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Example Parameterized Generation of XYZ Points for 3D Objects
// Zachary Johnson
// http://www.zachstronaut.com
var x, y, z, i = 250;
while (i--) {
/* random distribution /*
x = -125 + Math.round(Math.random() * 125 * 2);
y = -125 + Math.round(Math.random() * 125 * 2);
z = -Math.round(Math.random() * 250);
*/
/* galaxy /*
x = 17500 * Math.cos(i * 0.8) / (i + 100) - 5 + Math.random() * 10;
z = -150 + 17500 * Math.sin(i * 0.8) / (i + 100) - 5 + Math.random() * 10;
y = -25 + Math.round(Math.random() * 25 * 2);
*/
/* funnel or black hole /*
x = 7500 * Math.cos(i) / (i);
z = 7500 * Math.sin(i) / (i);
y = i;
//also
x = 17500 * Math.cos(i * 0.8) / (i + 100) - 5 + Math.random() * 10;
z = -150 + 17500 * Math.sin(i * 0.8) / (i + 100) - 5 + Math.random() * 10;
y = i * 0.3 + -25 + Math.round(Math.random() * 25 * 2);
*/
/* corkscrew, spiral /*
y = i; // or can be random
x = Math.cos(0.1 * y) * 50;
z = Math.sin(0.1 * y) * 50;
*/
/* somewhat galaxy-ish? /*
y = i; // or can be random
x = Math.tan(0.1 * y) * 50;
z = Math.sin(0.1 * y) * 50;
*/
/* ring, cylinder /*
y = i;
x = Math.cos(y) * 150;
z = Math.sin(y) * 150;
*/
/* cool loop /*
x = 150 * Math.cos(i) * Math.sin(i);
y = 150 * Math.sin(i) * Math.sin(i);
z = 150 * Math.cos(i);
*/
/* bowtie, hourglass /*
z = 150 * Math.sin(i);
x = 150 * Math.cos(z) * Math.sin(i);
y = 150 * Math.sin(z) * Math.sin(i);
*/
/* cluster /*
z = i * Math.cos(i);
x = i * Math.cos(z) * Math.sin(i);
y = i * Math.sin(z) * Math.sin(i);
*/
/* sphere /**/
// z = 150 * Math.cos(i);
// x = 150 * Math.cos(z) * Math.sin(i);
// y = 150 * Math.sin(z) * Math.sin(i);
// also:
z = 0.3 * 150 * Math.cos(i);
x = 0.3 * 150 * Math.cos(Math.PI * 2 * i / (0.3 * 250)) * Math.sin(i);
y = 0.3 * 150 * Math.sin(Math.PI * 2 * i / (0.3 * 250)) * Math.sin(i);
// also:
// z = 150 * Math.cos(Math.PI * i / 250);
// x = 150 * Math.cos(i) * Math.sin(Math.PI * i / 250);
// y = 150 * Math.sin(i) * Math.sin(Math.PI * i / 250);
/**/
// Do what you want with x, y, z here
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment