Rounded rectangles [Finally Solved, see last post]

Programming, for all ages and all languages.
osmiumusa
Posts: 20
Joined: Sun Dec 12, 2010 5:47 pm

Re: Rounded rectangles

Post by osmiumusa »

I still have no clue ways going on. Does anyone else?
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: Rounded rectangles

Post by Combuster »

There are so many better and worse solutions provided that you should be able to figure out at least one solution.

Do you have by any chance a graphical calculator or some other tool that can plot parametric functions? That makes testing equations a lot easier.
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
osmiumusa
Posts: 20
Joined: Sun Dec 12, 2010 5:47 pm

Re: Rounded rectangles

Post by osmiumusa »

Oooooooh. Good idea. It takes a w =D> hile to compile the OS. I'm working on a solution, believe me. :mrgreen:
osmiumusa
Posts: 20
Joined: Sun Dec 12, 2010 5:47 pm

Re: Rounded rectangles

Post by osmiumusa »

SOLVED IT!!! I took the midpoint circle algorithm and split it up into four parts, just like your suggestions. Thank you to everybody so much. I pasted the code if anyone else searched rounded rectangles like I did, but this time, they'll get a result! Thank you to everybody for helping me in seeking this answer!

~osmiumusa :mrgreen:

It may not be correct syntax (doesn't declare vars, etc.), but its helpful. Convert it to any language you like. :D

Code: Select all

//void drawRoundedRectangle(int x0, int y0, int x1, int y1, int radius)
  f = 1 - radius;
  ddF_x = 1;
  ddF_y = -2 * radius;
  xx = 0;
  yy = radius;
 
  draw_point(x0, y0 + radius); //bottom dot
  draw_point(x0, y0 - radius); //top dot
  draw_point(x0 + radius, y0); //right dot
  draw_point(x0 - radius, y0); //left dot
 
while(xx < yy)
  {
    // ddF_x == 2 * x + 1;
    // ddF_y == -2 * y;
    // f == x*x + y*y - radius*radius + 2*x - y + 1;
    if(f >= 0) 
    {
      yy-=1;
      ddF_y += 2;
      f += ddF_y;
    }
    xx+=1;
    ddF_x += 2;
    f += ddF_x;    
    draw_point(x1 + xx - radius, y1 + yy - radius); //Bottom Right Corner
    draw_point(x1 + yy - radius, y1 + xx - radius); //^^^
    draw_point(x0 - xx + radius, y1 + yy - radius); //Bottom Left Corner
    draw_point(x0 - yy + radius, y1 + xx - radius); //^^^
    draw_point(x1 + xx - radius, y0 - yy + radius); //Top Right Corner
    draw_point(x1 + yy - radius, y0 - xx + radius); //^^^
    draw_point(x0 - xx + radius, y0 - yy + radius); //Top Left Corner 
    draw_point(x0 - yy + radius, y0 - xx + radius); //^^^
  }
  draw_line(x0+radius,y0,x1-radius,y0); //top side
  draw_line(x0+radius,y1,x1-radius,y1); //botom side
  draw_line(x0,y0+radius,x0,y1-radius); //left side
  draw_line(x1,y0+radius,x1,y1-radius); //right side
Post Reply