|
|
| Angular timer and how to convert to a rect using an angular algorithm... |
|
Don Freeman
Member #5,110
October 2004
|
Hello again all! Does anyone have any ideas / suggestions on how to write this to do the
Be nice about the code please, it is only a quick and dirty test...::) -- |
|
gnolam
Member #2,030
March 2002
|
Quote: Also, any suggestions on how to simplify the math would be great.
Quote:
Does anyone have any ideas / suggestions on how to write this to do the The easiest way? Just use a sub bitmap. But before you write another line of code, I suggest you enable compiler warnings. Also, use a non-ancient version of Allegro. And stop inserting manual linebreaks into your posts. -- |
|
Andrei Ellman
Member #3,434
April 2003
|
Another way is to use the tan() of the angle to find out how far along each edge you have to draw the line. The following assumes that the angle of 0 corresponds to a line pointing rightwards and the line rotates anticlockwise as the angle increases. You will have to divide the rectangle into four quadrants because for each quadrant (note that these quadrants do not correspond to what are usually referred to as quadrants when discussing trigonometric functions), you want to trace round a different edge of the rectangle. To find the angular border to separate the quadrants, work out the inverse tangent of the horizontal distance from the rectangle-centre to the rectangle-edge divided by the vertical distance from the rectangle-centre to the rectangle-edge (this can be done using the atan2()) function. This will give you the boundry angle (B). That is, one quadrant boundry is at B, the other at 2pi-B, one is at pi+B and the last one at pi-B. If the angle lies in the first quadrant, multiply the horizontal distance from the rectangle-centre to the rectangle-edge by the tan() of the angle to get the Y coordinate on the rectangle's right edge to draw the line to. If in the second quadrant, multiply the vertical distance from the rectangle-centre to the rectangle-edge by tan((pi/2)-angle). For the third quadrant, -horizontal_distance * tan(angle), and for the fourth, -vertical_distance * tan(-(pi/2)-angle). Note that this is unchecked. AE. -- |
|
|