2

The following C code will draw a rectangle. I know how to draw the ellipse, but how can i draw an ellipse into this rectangle?

#include<graphics.h>
#include<conio.h>

main()
{
   int gd = DETECT, gm;

   initgraph(&gd, &gm, "C:\\TC\\BGI");

   rectangle(100,100,200,200);

   getch();
   closegraph();
   return 0;
}
genpfault
  • 51,148
  • 11
  • 85
  • 139
TPSstar
  • 121
  • 1
  • 13

1 Answers1

1

Asuming you're using the ellipse function from graphics.h, you could do the following:

 int left = 100;
 int right = 200;
 int top = 100;
 int bottom = 200;

 rectangle(left, top, right, bottom);

 int x = (left + right) / 2;  
 int y = (top + bottom) / 2;  
 int start = 0;
 int end = 360;
 int xrad = (right - left) / 2;
 int yrad = (bottom - top) / 2;

 ellipse(x, y, start, end, xrad, yrad);
higuaro
  • 15,730
  • 4
  • 36
  • 43
  • So, there's no rocket science :D i only need to reduce its size to display into the rectangle? – TPSstar Nov 26 '12 at 17:33
  • Sorry, didn't see the comment until now. Basically, you are inscribing the ellipse into the rectangle, if you need to shrink the ellipse then use shrinked version of `left`, `right`, `top` and `bottom` for the ellipse and the real version for rectangle – higuaro Dec 03 '12 at 18:01