Public Group

# [OpenGL] i need a tip

This topic is 3818 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hello guys, i am studying opengl for 3 weeks on the red book, at the moment i am in chapter 5 (the lights). I am doing this since it's part of the final work for my degree. Now my teacher wanna me to do a particular thing; i'll past the exacts words: "draw (even in wireframe) a sphere composed by many triangles or quads. If u succeed, try to deform the sphere (matematecally, changing the the calc of the vertices's positions of the triangles) so that the sphere will appear squeezed on the poles. If u wanna amaze me, the sphere has to appear concave on the 2 poles". Ok i have to draw manually the spere, avoiding the use of glut*Sphere. I did it last week using a Icosahedron (it's in chapter 2 of the red book). The verteces of such object are khnown, so i described the verteces thrawning opengl the coords of each vertex, i.e: glBegin (GL_TRIANGLES); ... vertices (in the right order) .... glEnd(); Here there is no math calculation but. What sort of math manipulation can i do here? There is no a function or something like that. So reading what my teacher wrote, i think he wants a different way to draw this sphere. I don't khnow but i.e. it sounds like drawning a circle specifying manually the vertices and drawning a circle with a cicle and sin/cos. Do u agree with me? I think someone with more experience than me can imagin what my teacher's words mean. I hope i have been clear. Bye and thanks guys bro Edit: error in the post title [Edited by - broady on June 26, 2008 5:39:53 AM]

##### Share on other sites
Well, the positions for the vertices that make up a sphere can be calculated using sin and cos. (That way, the sphere will look like it has the latitude/longitude lines on a standard globe). By changing the parameters a bit (actually, the scaling), you can flatten the sphere, which is what I think he means.

For more information on the math behind spheres: check out Wikipedia. It has a simple set of equations for x, y and z where all you need to do is loop over the angles (φ and θ).

If you scale the height component (in the Wikipedia example: z) so it isn't solely dependent on the elevation angle (θ), but also on the distance of that point to the Z axis, the sphere will become concave at the poles (like an apple).

##### Share on other sites
I think he means you have to apply some transformation to the vertices so that from a side-view the sphere does look like an elipsis ("sphere will appear squeezed on the poles").

You basically set the vertices by calculating the coords with sin() and cos() and vary the z-value to squeeze the sphere.

Look at my "beautiful" ascii representation of what he wants:
orinial sphere:     xx  xxxxxxxx xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxxxx  xxxxxxxx     xxsqueezed sphere:   xxxxxx xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxxxx   xxxxxxconcave sphere:        x    x xxxx  xxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxx  xxxx   x    x

##### Share on other sites
That's an oblate spheroid.

##### Share on other sites
Nice guys,

i will first draw a sphere with sin and cos. Later i will focus on the squeeze.
Thanks

##### Share on other sites
Ciao
If you want to draw a sphere, the simpler way is to use a parametric equation. A common one is the following:

x = R*cos(φ)cos(θ);
y = R*cos(φ)sin(θ);
z = R*sin(φ);

where R is the radius, 0 <= φ < π, 0 <= θ < 2π.

To modify the form of the sphere you can apply a transformation to the sphere or use a function that depends on the angles instead of a constant radius in the formula above.

Edit: You can try working on functions like R(φ) = m + n*sin(φ)k where m,n and k are constants to modulate the point on the sphere. Those functions have a minimum in φ = 0 and and maximum in φ = π/2. When k > 1 the derivatives in 0 and π are k*cos(φ)*sin(&phi)k-1 = 0 and the poles look better (if k = 0 the two derivatives have different signs).

[Edited by - apatriarca on June 26, 2008 6:09:28 AM]

##### Share on other sites
Quote:
 Original post by apatriarcaCiaoIf you want to draw a sphere, the simpler way is to use a parametric equation. A common one is the following:x = R*cos(φ)cos(θ);y = R*cos(φ)sin(θ);z = R*sin(φ);where R is the radius, 0 <= φ < π, 0 <= θ < 2π.To modify the form of the sphere you can apply a transformation to the sphere or use a function that depends on the angles instead of a constant radius in the formula above.Edit: You can try working on functions like R(φ) = m + n*sin(φ)k where m,n and k are constants to modulate the point on the sphere. Those functions have a minimum in φ = 0 and and maximum in φ = π/2. When k > 1 the derivatives in 0 and π are k*cos(φ)*sin(φ)k-1 = 0 and the poles look better (if k = 0 the two derivatives have different signs).

Ciao apatriarca, thanks for the replay!

yeah i am working on that parametrization from this morning. I have some problem connecting the vertices with lines but i will win :D

bye

##### Share on other sites
The best way to understand how to define the polygons is breaking the solid and see it as a set of connected polygons on a piece of paper. If you deform the polygons you should obtains something like that:

1. 1
2. 2
Rutin
29
3. 3
4. 4
5. 5
khawk
14

• 11
• 11
• 23
• 10
• 9
• ### Forum Statistics

• Total Topics
633648
• Total Posts
3013111
×