Archived

This topic is now archived and is closed to further replies.

Gyzmo

Spheres

Recommended Posts

Gyzmo    162
I''d like a function that generates a (triangulated)sphere, like in 3d-modeling programs where you say ''Give me a sphere with X-segment or detail level X'' if you know an algo, or a link to info I''d appreciate it. Gyzmo ======================== Having a ''sig''-crisis

Share this post


Link to post
Share on other sites
federickrex    122
it'' simple...
you have to think thata a sphere is like Earth: you can subdivide it in many squares like latitude e longitude.

every square has 4 vertex and 2 triangle that link them.
eache vertex may be opthaind so:

for(i = 0; i < x; i++){
for(j = 0; j < x; j++){
latitude = (6.28 / x * i);
longitude = (3.14 / x * j);
vertex[j].x = sin(latitude)*cos(longitude)*radius;
vertex[i][j].y = sin(longitude)*radius;
vertex[i][j].z = cos(latitude)*cos(longitude)*radius;
}
}

then every triangle links three vertex, and every for vertex make a square:


vertex[i][j], vertex[i+1][j], vertex[i+1][j+1] vetrex[i][j+1] make a square.

fede

Share this post


Link to post
Share on other sites
Gyzmo    162
quote:
Original post by federickrex
for(i = 0; i < x; i++){
for(j = 0; j < x; j++){
latitude = (6.28 / x * i);
longitude = (3.14 / x * j);



Thanks, I haven''t tried it, but this WILL give a division by zero, I take it it must be something like


for(i = 1; i <= x; i++){
for(j = 1; j <= x; j++){
latitude = (6.28 / x * i);
longitude = (3.14 / x * j);


am I right?

Share this post


Link to post
Share on other sites