Author Topic: Rotating Rectangle  (Read 2481 times)

0 Members and 1 Guest are viewing this topic.

Offline mike_g

  • Amiga 1200
  • ****
  • Posts: 435
  • Karma: 34
    • View Profile
Rotating Rectangle
« on: January 07, 2007 »
I would like to find out how I could make a filled rotateable rectange function. My idea was that the function could have 5 parameters like: ROT_RECT(x, y, width, height, angle). which rotates around the center point. Help would be much appreciated.

Offline Jim

  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 5301
  • Karma: 402
    • View Profile
Re: Rotating Rectangle
« Reply #1 on: January 08, 2007 »
The 4 points are
Code: [Select]
s = sin(angle)
c = cos(angle)

sw = width * s
cw = width * c

sh = height * s
ch = height * c

(x,y)
(x+cw,y+sw)
(x+cw-sh,y+sw+ch)
(x-sh,y+ch)


You can join them together with lines.  To fill it you really need a triangle drawing routine.

Jim

Challenge Trophies Won:

Offline mike_g

  • Amiga 1200
  • ****
  • Posts: 435
  • Karma: 34
    • View Profile
Re: Rotating Rectangle
« Reply #2 on: January 08, 2007 »
Thanx. I got a function that draws filled triangles so I can just do two of them using co-ordinates got by that code.