Sunday, June 10, 2012

Circles are Easier than Spheres

‹prev | My Chain | next›

It seems that access to CubicVR.js primitives is somewhat difficult in Gladius now. This makes generating things like spheres problematic. Still, I would like to give it a go.

As I found yesterday, CubicVR spheres are just a specific case of "lathe" objects. I should probably understand those better, but, for now, I will content myself with generating a sphere. Actually, to get started, I am not even going to do that. For now, I will just content myself with a circle.

So I work around 24 points of 360° (or 2*PI radians). The x coordinate is the cosine of the current angle, the y coordinate is the sine:
function proc(options) {
  var M_TWO_PI = 2.0 * Math.PI;

  var points = [[0,0,0]],
      faces = [[0,1,24]];

  for (var i=1; i<=24; i++) {
    points[i] = [
      Math.cos(M_TWO_PI * i/24),
      Math.sin(M_TWO_PI * i/24),
    if (i > 1) {
      faces[i-1] = [0, i, i-1];

  var mesh =
    points: points,
    faces: faces,
    wireframe: true

  return mesh;
For the "faces", I am building a triangle for each portion as I work around the 24 parts of the entire 360°. The vertex of the triangle is the center of the circle and the two corners are the current point and the last one that I added to the list of points.

With that, I get my circle spinning around:

OK, feeling a little better about this stuff. Tomorrow, I will add a third dimension to build up a sphere.

Day #413

No comments:

Post a Comment