Jump to content
  • Advertisement
Sign in to follow this  
yakovm

OpenGL surface area calculation

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello
I use glDrawArrays(GL_POINTS,...) to draw harmonic wave.
I would like to know the order in which the surfaces (triangles?) are generated by openGL while rendering based on the vertices
and in such a way calculate the surface area?
Can I do it and if yes how.

Share this post


Link to post
Share on other sites
Advertisement
[font=arial, verdana, tahoma, sans-serif][size=2]Am I understanding right that you have a 2D array of values you can look up like a function: f(u,v) = some vertical displacement value at u and v ?[/font][font=arial, verdana, tahoma, sans-serif][size=2]

If that's the case, finding the volume under the surface is very easy, it's just a simple integral. It will come out to summing all the values, and then multiplying by some scaling factor. (The scaling factor depends on your delta u and delta v). Also, you have to keep in mind that you have decide on a lower bound for the bottom of the volume, because technically there is infinite volume under a surface. [/font]

Surface area is a bit more complicated. There is a little blurb in wikipedia about it here: http://en.wikipedia.org/wiki/Parametric_surface

Since you are solving this numerically with a grid of discrete values, it would be very easy to create a grid of triangles (as if you would render the surface), and just add up the area of all the triangles.

Share this post


Link to post
Share on other sites

Since you are solving this numerically with a grid of discrete values, it would be very easy to create a grid of triangles (as if you would render the surface), and just add up the area of all the triangles.


Can you give me a clue how to do it also can you look at my edited post I have edited it before I saw your answer

Share this post


Link to post
Share on other sites
Can you post a screenshot of the wave? I just want to see what we're dealing with.

I imagine you are rendering something like this:


glBegin(GL_POINTS);

for (i=0;i<=imax; i++)
{
for (j=0;j<=jmax;j++)
{
float u = uscale * ( i / (float) imax) + uoffset;

float v = vscale * ( j / (float) jmax) + voffset;

float h = calculate_one_harmonic_wave_point(u,v);

glVertex3f (u, h, v);

}
}

glEnd();



Can you post your calcuation / rendering code?

If you can reorganize it so you are drawing the surface as triangles instead of points, then calculating the area of each triangle will be easy.

Share this post


Link to post
Share on other sites

Can you post a screenshot of the wave? I just want to see what we're dealing with.

I imagine you are rendering something like this:


glBegin(GL_POINTS);

for (i=0;i<=imax; i++)
{
for (j=0;j<=jmax;j++)
{
float u = uscale * ( i / (float) imax) + uoffset;

float v = vscale * ( j / (float) jmax) + voffset;

float h = calculate_one_harmonic_wave_point(u,v);

glVertex3f (u, h, v);

}
}

glEnd();



Can you post your calcuation / rendering code?

If you can reorganize it so you are drawing the surface as triangles instead of points, then calculating the area of each triangle will be easy.

I dray it this way:

[font="Consolas"][font="Consolas"]glDrawArrays(GL_POINTS, 0, WINDOW_WIDTH * WINDOW_HEIGHT);

[/font][/font][font="Consolas"][font="Consolas"]While the formula too generate the array of points is as you mentioned in your code.

[/font][/font]

[font="Consolas"][font="Consolas"]I understand that is something very simple though I don't understand how to it exactly[/font][/font]

Share this post


Link to post
Share on other sites
So for clarity I'm going to use this point structure:

typedef struct point_s
{
float x,y,z;
}
point_t;



I'm also going to assume points are laid out in a two dimensional array. That way I can refer to specific point coordinates easily, such as point[j].z
In reality, you probably have all the data in one flat array, which is how opengl prefers it anyway. In that case point[j].x/y/z would have to be flattened down into something like myarray[ 3* ( i + j*(imax+1) ) + Q], where Q is 0 for x, 1 for y and 2 for z. But these are all arcane details.

So, on to the array of points:


i=0 1 2 imax-1 imax
j=0 *---*---*- ... --*---*
| / | / | ... / | / |
1 *---*---*- ... --*---*
| / | / | ... / | / |
2 *---*---*- ... --*---*

... ... ... ... ...

jmax-1 *---*---*- ... --*---*
| / | / | ... / | / |
jmax *---*---*- ... --*---*



So, first thing to notice is if we have have an N by N grid of points, we will have an N-1 by N-1 grid of squares. I've split each square arbitrarily; I could have decided to split using the other diagonal instead. That isn't actually important at the moment. (Although it may actually alter the surface area results slightly.)

So, for all i and j from 0 to imax-1, jmax-1, we can define the two triangles like this:

Triangle 1: point[j] point[i+1][j] point[j+1]
Triangle 2: point[i+1][j+1] point[i+1][j] point[j+1]

If you can get your app drawing the surface correctly with triangles (to do a visual confirmation you're picked all the right points for each triangle), now you can appropriate the surface area of the wave by calculating the area of each triangle and then adding them together.

Here is a link to information on how to calculate the area of a triangle in 3d given the three points:

http://softsurfer.co...ern%20Triangles

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!