<- previous    index    next ->

Lecture 23, Computing Volume and Area


Some volumes and areas you should already know:

area of a triangle is 1/2 base times height

                             |  1   1   1 |
area of a triangle is 1/2 det| x1  x2  x3 |
                             | y1  y2  y3 |

area of a triangle is |(V2 - V1) x (V3 - V1)|  length of cross product

area of a rectangle is base times height
area of a parallelogram is base times height 
area of a circle is  Pi r^2


Some variations that you may need some day:

You may not know the area of a five point star inscribed in
a unit circle or the area of an arbitrary closed polygon.

Easy to calculate, using the sailors algorithm:

Given the n points (x,y) of a closed polygon where no edges cross,
compute the sum i=1..n  (x_i+1 - x_i) * (y_i+1 + y_i)/2
(The first point is repeated as the n+1 point,
 add enough to the y's to make them all positive)

The computed area will be positive if an upper outside edge is
listed in counter clockwise order, else negative.

A  sample program is:
poly_area.c
poly_area_maze.out
maze.path
poly_area_star.out
star.path

The maze is:

The star is:



Volume of a sphere  4/3 Pi r^3
Area of a sphere    4 Pi r^2
Volume of a cone, tetrahedron, any solid with a planar base that goes
to a point  1/3 base area times height


                                |  1   1   1   1 |
Volume of a tetrahedron 1/6 det | x1  x2  x3  x4 |
                                | y1  y2  y3  y4 |
                                | z1  z2  z3  z4 |


The general volume computation of a closed surface is a little more
complicated. The sailors algorithm is still the basic idea.

Consider a closed surface covered by triangles. Each triangle is
three points and are coded counter clockwise such that the normal
vector to the triangle points out of the volume.

Make all z coordinates positive.
Compute the average z for a triangle.
Compute the area for a trinagle.
Compute the z component of the normal vector, znorm.
The volume of this peice of the surface is
   average z  times  area  times znorm

If znorm is positive, this triangle is on top and contributes
positive volume.
If znorm is negative, this triangle is on the bottom and
contributes negative volume.
The area in the x-y plane is the area of the triangle times znorm.
A vertical triangle has znorm = 0.
A horizontal triangle has znorm = 1 on top and -1 on bottom.
A triangle tipped 45 degrees has a znorm = cos(45 degrees) = 0.7071

A program that uses graphics data files to compute the volume and
area of a closed volume is:
volume_dat.c
output for a crude, 32 triangle, sphere is:

volume_dat.c reading sphere_div.dat 
status=0, size=1
final total area = 10.4178, total volume = 2.94281 


from data:
sphere_div.dat

output for a 2048 triangle sphere is: 

volume_dat.c reading sphere_div4.dat 
status=0, size=1
final total area = 12.5264, total volume = 4.16424 

from data:
sphere_div4.dat

The volume of a perfect sphere of radius 1 is about 12.56
The area of a perfect sphere of radius 1 is about 4.189

    <- previous    index    next ->

Other links

Go to top