Rounded rectangles [Finally Solved, see last post]
Re: Rounded rectangles
I still have no clue ways going on. Does anyone else?
- Combuster
- 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
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.
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
Oooooooh. Good idea. It takes a w hile to compile the OS. I'm working on a solution, believe me.
Re: Rounded rectangles
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
It may not be correct syntax (doesn't declare vars, etc.), but its helpful. Convert it to any language you like.
~osmiumusa
It may not be correct syntax (doesn't declare vars, etc.), but its helpful. Convert it to any language you like.
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