Page 3 of 3

Re: Rounded rectangles

Posted: Thu Apr 21, 2011 5:13 am
by osmiumusa
I still have no clue ways going on. Does anyone else?

Re: Rounded rectangles

Posted: Thu Apr 21, 2011 9:20 am
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.

Re: Rounded rectangles

Posted: Thu Apr 21, 2011 1:32 pm
by osmiumusa
Oooooooh. Good idea. It takes a w =D> hile to compile the OS. I'm working on a solution, believe me. :mrgreen:

Re: Rounded rectangles

Posted: Sun May 08, 2011 7:52 pm
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