Howdy, Stranger!

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

Sign In with Facebook Sign In with Google Sign In with OpenID

Categories

We have migrated to a new platform! Please note that you will need to reset your password to log in (your credentials are still in-tact though). Please contact lee@programmersheaven.com if you have questions.
Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

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



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)


Comments

  • 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


  • : 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








Sign In or Register to comment.