How to build sphere from triangles? - Algorithm, anyone? Or source? - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

How to build sphere from triangles? - Algorithm, anyone? Or source?

Guest

Need to build sphere (any kind of) by triangles...I need algorithm ,not 3DS format reader or ASCII file with vertexes... Anyone did it before (or doing?)

How 3DStudio builds a sphere from triangles...I want that too...

8)

• Guest
3d studio has 2 types, geosphere and normal sphere

geosphere is a bit more comlicated, so i don't

know that one either :-)

but the normal sphere is actually quite easy

what you have is a ball with lines on it...

you probably have seen a globe, right? (i mean

with the world on it) there you also have those

lines. say you divide the sphere in 16 parts

horizontal and 16 parts vertical.

that means 16 lines vertical and 16 lines horizontal.

but the ones on top and bottom are actually all

the same, think of the lines on the globe coming

together at the poles

(are you still with me?)

so now all you have to do is place a vertex

at each point where those lines cross.

and there we have a little bit of math

(very small bit)

and i don't know if this is correct since i do

it from memory

(you must tweak the sines a bit)

for (int y=0; y<16; y++) {<br>
for (int x=0; x<16; x++) {<br>
mul = size*sin(y);

vertex[next].x = size*sin(x);

vertex[next].y = size*cos(x);

vertex[next].z = y;

}

}

but then, this could all be wrong :-)

ile / aardbei

• Guest
: 3d studio has 2 types, geosphere and normal sphere

: geosphere is a bit more comlicated, so i don't

: know that one either :-)

here it is:

make the simplest possible object: a pyramid with a triangle as a base. This object has 4 faces. Then you collaps all faces into 4 new faces.

/

/

/____

/ /

/ /

/____/____

excuse the ascii

So now you have 4x4 = 16 faces.

next step, 64, then 256, etc etc... until you have the amount of faces you like/want.

But this is not a sphere, just a lame pyramid made up from a lot of faces. You can make it a sphere by normalizing all vertices (make them unit length), and then multiplying them by the desired radius.

for you lamers who dont know how to normalize a vector ...

length = sqrt(x*x+y*y+z*z)

x /= length

y /= length

z /= length

thats it...

/inopia