View Full Version : bending a rectangle
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 ?
02-27-2004, 08:51 PM
Assuming rw, and rh for rectangle width and height. "angle" is the bend variable in radians.
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
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.
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.
You could use OpenGL evaluators for this task
thanks I have never heard of these... I will check it out
this is what im trying to accomplish :
03-02-2004, 04: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.
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.
03-02-2004, 02: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;
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..
i really appreciate your help!!
It's all done.... perfect thanks!!
03-04-2004, 03:48 AM
I just saw the image with the bent polygon. Trully groovy!
heres a screenshot update with the bending arrow.. it bends left right then up and down starting from the halfway point..
Powered by vBulletin® Version 4.2.2 Copyright © 2015 vBulletin Solutions, Inc. All rights reserved.