karthick
karthick

Reputation: 12176

Can anyone explain this snippet of Javascript?

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);
  }
}

Upvotes: 0

Views: 146

Answers (2)

Artelius
Artelius

Reputation: 49078

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

objectsInScene is an array of all these objects.

Upvotes: 3

Brock Adams
Brock Adams

Reputation: 93443

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

Upvotes: 2

Related Questions