tags:

views:

103

answers:

2

Can anyone explain the following code? Forget the sine and cosine parts. Is it trying to build a space for the object?

objectsInScene = new Array();

for (var i=space; i<180; i+=space) {

  for (var angle=0; angle<360; angle+=space) {

    var object = {};

    var x = Math.sin(radian*i)*radius;
    object.x = Math.cos(angle*radian)*x;
    object.y = Math.cos(radian*i)*radius;
    object.z = Math.sin(angle*radian)*x;
    objectsInScene.push(object);
  }
}
+3  A: 

If I'm not much mistaken it's arranging objects in a hemispherical shape.

objectsInScene is an array of all these objects.

Artelius
Thank you guys..
@karthick6891: You're welcome. If you are happy with the response, please mark one of the answers with the check box. *I shamelessly recommend marking Brock Adams' answer!* :) If you are not happy with the answer comment as to why not.
Brock Adams
Yeah, Brock clearly needs the rep more than I do ;)
Artelius
+2  A: 

It's filling objectsInScene with a sphere of points (not a hemisphere), spaced space degrees apart. The diameter is 2 times radius.

Brock Adams
D'oh, you're right of course.
Artelius