javascript - How to draw a Sphere without using SphereGeometry? -


i'm trying draw sphere without using spheregeometry. i'm trying draw sphere latitudes , longitudes. here code:

for (var phi = -math.pi / 2; phi < math.pi / 2; phi += math.pi / 15) {                     var longvertices = new three.geometry()                     (var theta = 0; theta <= 2 * math.pi; theta += math.pi/2 ) {                          longitudes = this.point[this.numberofvertices] = new three.vector3();                          longitudes.x = origin.x + this.radius * math.cos(theta) * math.cos(phi);                         longitudes.y = origin.z + math.sin(theta) * this.radius;                         longitudes.z = origin.y + this.radius * math.cos(theta) * math.sin(phi);                          this.numberofvertices++;                         longvertices.vertices.push(longitudes);                     }                     longvertices.vertices.push(longvertices.vertices[0]);                     longverticesarr.push(longvertices);                 } 

this code helps me draw longitudes. enter image description here

and:

        (var phi = -math.pi / 2; phi < math.pi / 2; phi += math.pi / 15) {              var delta = math.cos(phi) * this.radius;             var fixedy = math.sin(phi) * this.radius * direction;             var latvertices = new three.geometry();             (var theta = 0; theta < 2 * math.pi; theta += math.pi / 10) {                 latitudes =/* this.point[this.numberofvertices] =*/ new three.vector3();                  latitudes.z = origin.z + delta * math.sin(theta);                 latitudes.y = fixedy;                 latitudes.x = origin.x + delta * math.cos(theta);                  this.numberofvertices++;                  latvertices.vertices.push(latitudes);                }             latvertices.vertices.push(latvertices.vertices[0]);             latverticesarr.push(latvertices);          } 

this helps me draw latitudes.

enter image description here

now problem i'm facing i'm not getting points of both latitudes , longitudes @ intersection. how these points @ intersection?

simple nested loop: [ http://jsfiddle.net/cdjtdkwa/ ]

var r = 18; // radius var lon = 32; var lat = 16; // approximation var pilat = math.pi/lat; var pilon = 2*math.pi/lon;     var cos1,cos2,sin1,sin2,t1,t2;     var y1,y2,r1,r2,t1,t2;     var geometry = new three.geometry();  (var i=0; i<lat; i++) { // walk latitudes segments     t1 = math.pi - i*pilat;     t2 = math.pi - (i+1)*pilat;      y1 = math.cos(t1); // 1 latitudes radius y-position;     y2 = math.cos(t2); // 2 latitudes radius y-position;      r1 = math.abs( math.sin(t1) ); // 1 latitudes radius;     r2 = math.abs( math.sin(t2) ); // 2 latitudes radius;                (var j=0; j<lon; j++) { // walk longitudes segments         t1 = j*pilon;         t2 = (j+1)*pilon;          cos1 = math.cos(t1);         cos2 = math.cos(t2);         sin1 = math.sin(t1);         sin2 = math.sin(t2);          geometry.vertices.push(             new three.vector3( r1*cos1, y1, r1*sin1 ),             new three.vector3( r2*cos1, y2, r2*sin1 ),             new three.vector3( r2*cos2, y2, r2*sin2 )                   );      } } 

Comments

Popular posts from this blog

dns - How To Use Custom Nameserver On Free Cloudflare? -

python - Pygame screen.blit not working -

c# - Web API response xml language -