#### Archived

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

# drawing a curved surface

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

## Recommended Posts

I urgently want to draw a 3D curved surface that is essentially a 1/4 of a hollow cylinder. How do i do that? Will appreciate if there is any sample tutorial or code. Thank you.

##### Share on other sites
quote:
Original post by coda_x
I urgently want to draw a 3D curved surface that is essentially a 1/4 of a hollow cylinder. How do i do that? Will appreciate if there is any sample tutorial or code. Thank you.

So this surface would kind of look like a piece of paper with it's long sides lifted up slightly?

You could do it like this... (assuming you want it concave up)

for t = 0 to length

x[t] = width * cos(t)
y[t] = -1 * height * sin(t)
z[t] = t

loop

And then to draw it you could just stitch each length of t together with triangles

You know what I mean?

[edited by - nexius on January 12, 2004 2:41:53 AM]

##### Share on other sites
yah it looks like a paper with sides lifted up slightly but erm I dun understand what t stands for - radius? is there a proper code for it? i am doing for a project and been stuck here. Thanx.

##### Share on other sites
I think t in that case would be the arc-length. He's using t for the cos/sin parameter, so it's representing the angle. If t went from 0 to 2*PI, you'd get a full cylinder. One way you could accomplish this is make a grid of vertices. Think of the grid of vertices as the piece of paper, but you've folded it upwards.

// Generic 3-float vertex structstruct Point{    float x, y, z;};// 50 vertices along the arc, 100 vertices in lengthPoint VertexGrid[50][100];// This is the angle variablefloat t;// Fill the gridfor (int z = 0; z < 100; z++) // loop for the length of it{    t = 0.0f;    for (int x = 0; x < 50; x++) // loop from right to left    {        // Have t increment from 0 rads to PI over the width        t = (float)x / 49 * PI;        VertexGrid[x][z].x = cos(t) * radius;        VertexGrid[x][z].y = -sin(t) * radius;        VertexGrid[x][z].z = -(float)z / 99 * length;    }}

Unless I did something horribly wrong, that grid would now represent a half cylinder (since I went from 0 to PI rads) opening upwards (note the negative y value) and it'll stretch from z = 0.0 to z = -length (remember going into the screen is more and more negative along the z-axis).

Once you have the grid, you could write a connectivity loop to generate the triangles for rendering. If you need that too, go ahead and ask.

That help?

Edit: I noticed you asked for 1/4 of a cylinder, so replace that PI value in the inner loop with PI / 2, i.e. 1/4 of a full circle. That should do it

[edited by - chawk on January 12, 2004 10:01:05 AM]

##### Share on other sites
thanx that help to clear up my doubt can i ask how do u render it? is it

gl_Begin(GL_TRIANGLE_FAN);

erm then i not sure how to continue...btw the code u wrote can I put it in function then call it here? also, i need the normal to this curve surface as I am using lighting, how to do this as well? greatly appreciate any kind help

[edited by - coda_x on January 12, 2004 8:34:24 PM]

1. 1
Rutin
46
2. 2
3. 3
4. 4
5. 5

• 13
• 10
• 12
• 10
• 13
• ### Forum Statistics

• Total Topics
632995
• Total Posts
3009774
• ### Who's Online (See full list)

There are no registered users currently online

×