PDA

View Full Version : Inflate a polygon

chief
10-01-2002, 10:29 PM
First of all sorry for my poor english. Any one know a good thecnic to inflate a non self-intersecting polygon in 3D space (like the well know windows function InflateRect(rect,cx,cy))? Thanks in advance...

knackered
10-02-2002, 01:45 AM
You mean scale?
Or extrude each point along its surface normal?

jwatte
10-02-2002, 08:44 AM
glScalef() should do it just fine.

chief
10-02-2002, 10:47 PM
Scaling is not correct because the amount of inflating is not equal for each side of the polygon. My target is to obtain a inflated polygon in wich each side is parallel to the original and translated of the prescribed (de)inflating value delta. Sorry for my poor english chief

tarantula
10-03-2002, 12:03 AM
then you probably want to displace the vertex along the surface normal like knackered said. But if you want to do that for a mesh of polygons then you will need to displace the along the vertex normal or else you will get cracks in the mesh.

if you are looking for pseudo code..
V' = V + delta*N
V,V' the vectors pointing the vertex before and after inflating, N is the normal.

knackered
10-03-2002, 01:42 AM
I've just read the spec for the win32 InflateRect function. I'm still unsure what the difference between that method and a simple scale is...

jwatte
10-03-2002, 01:44 PM
InflateRect does just a scale. However, the original question also wants a solution to the problem for concave polygons (a rectangle is convex).

One algorithm is to split your concave polygon into convex pieces, inflate them all, and then merge them back.

Another algorithm is to describe the polygon as a series of planes; the translate the planes, and re-discover the polygon (a la BSP rendering).

knackered
10-03-2002, 02:16 PM
Actually, thinking about it, inflaterect does not do a scale. It adds values to the points rather than multiply the points by a scalar.
It seems to find the rough center of the polygon and, depending on each points position in relation to the center, add or subtract the constant 'inflation' value you supply it with.

The algorithm would then be this, for a 3d poly:-

- Add up all vertices, and divide by number of vertices to find the mean center vertex(and call it 'C')

- for each vertex in polygon
--- if (vert.x < C.x)
------ vert.x -= inflateval
--- else if (vert.x > C.x)
------ vert.x += inflateval
--- if (vert.y < C.y)
------ vert.y -= inflateval
--- else if (vert.y > C.y)
------ vert.y += inflateval
--- if (vert.z < C.z)
------ vert.z -= inflateval
--- else if (vert.z > C.z)
------ vert.z += inflateval

That should do it.

[This message has been edited by knackered (edited 10-03-2002).]

SirKnight
10-03-2002, 03:24 PM
Hey, you can use this technique to make clowns inflate 3d baloons in a circus game! heh heh http://www.opengl.org/discussion_boards/ubb/biggrin.gif

EDIT: Hehe, forgot the 2nd 'c' in circus. http://www.opengl.org/discussion_boards/ubb/wink.gif

-SirKnight

[This message has been edited by SirKnight (edited 10-03-2002).]