# The Industry's Foundation for High Performance Graphics

1. ## bending a rectangle

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 ?

2. ## Re: bending a rectangle

Assuming rw, and rh for rectangle width and height. "angle" is the bend variable in radians.
Code :
```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.

3. ## Re: bending a rectangle

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.

4. ## Re: bending a rectangle

You could use OpenGL evaluators for this task

5. ## Re: bending a rectangle

thanks I have never heard of these... I will check it out

6. ## Re: bending a rectangle

this is what im trying to accomplish :
http://www.koreproductions.com/temp/bentPolygon.jpg

7. ## Re: bending a rectangle

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.

8. ## Re: bending a rectangle

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.

9. ## Re: bending a rectangle

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.

Code :
```//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```

10. ## Re: bending a rectangle

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..