PDA

View Full Version : bending a rectangle

kore
02-26-2004, 11:54 AM
Hi,

here's what I'm trying to do, I want to have a rectangle gradually bend 45 degrees left and then gradually bend 45 degrees right.. I have a bend variable that goes from 0 to 45 back to 0 to -45 back to 0 and so on..

My original idea was to build a rectangle using multiple 4 point polygons, and depending on the variables make the z and x coordinates change depending on the bend.. I haven't been able to make anything decent looking or simulating a bend..

any ideas on an algorithm that could work for this or maybe an easier method ?

chemdog
02-27-2004, 09:51 PM
Assuming rw, and rh for rectangle width and height. "angle" is the bend variable in radians.

glBegin(GL_POLYGON);
glPoint2f(0,0); //bottom left
glPoint2f(rw,0); //bottom right
glPoint2f(rw + rh * sin(angle), rh); //top right
glPoint2f(0 + rh * sin(angle), rh); //top left
glEnd();

This will give a parallelogram, with equal opposite sides. When angle is 0, it is a rectangle. When angle is pi/4, (45 degrees), it is slanted to the right; is -pi/4, (-45 degrees), it is slanted to the left.

kore
02-29-2004, 09:34 AM
thanks for the answer... it is not quite what I was hoping to do though.

by bending i mean I want it to be curved, that's why I believe i will need multiple polygons to make up the bent rectangle.

mw
03-01-2004, 12:32 AM
You could use OpenGL evaluators for this task

kore
03-01-2004, 06:12 AM
thanks I have never heard of these... I will check it out

kore
03-01-2004, 08:52 AM
this is what im trying to accomplish :
http://www.koreproductions.com/temp/bentPolygon.jpg

vegark
03-02-2004, 05:09 AM
In OpenGL a polygon consists of several streight lines.

It's not possible to curve any "lines" in OpenGL. You need to split the line in several parts. Otherwise the geometry is to coarse.

kore
03-02-2004, 07:05 AM
ive now managed to create the arrow with several pieces, and somewhat simulate the bending in it real-time.. It still isn't as good looking as I want but It's a start.

chemdog
03-02-2004, 03:59 PM
To make a jello-like rectangle, you can use that single quad bending-code to create a series of stacked rectangles.
In the code angle brackets indicate positions, and addition is in position space; The angle array contains the angle for each slice. sh is the hieght of each slice.

//sh = rh / (last-first+1);
bottomleft = <0,0>;
bottomright = <rw, 0>;
for i = first to last
offset = <sh*sin(angle[i]), sh >;
topright = bottomright + offset;
topleft = bottomleft + offset;
DrawRectangle(bottomleft, bottomright, topright, topleft);
bottomleft = topleft; bottomright = topright;
//endloop

kore
03-02-2004, 08:25 PM
wow that worked great.. and much simpler than my original (headache of a method) way..

now, my only problem is with the tapered effect I want with my rectangle... I'm gonna work on this now, but if you have any ideas - let me know..

kore
03-03-2004, 08:18 PM
It's all done.... perfect thanks!!