## How to draw a circle on Timage object with given center and radius

### How to draw a circle on Timage object with given center and radius

Hello,
I want to draw a circle in borland c++ builder 6.0 on TImage object. I have got the information like center of the circle and radius. i couldn't found any circle fuction in BCB. Please help me. also i want to refresh the Image to clear the drawn object. I have tried refresh and repaint but couldn't succeed .

abhimanyu

### How to draw a circle on Timage object with given center and radius

a little piece of code riarranged for you, maybe can contain sintax error
but the algorithm is correct

#define rad2gr(y) (float)(((double)y * (double)180.0) / (double)M_PI)
#define gr2rad(y) (float)((double)y * ((double)M_PI / (double)180.0))
int px, py;
bool first = true, close=false;
{
for (angle=angleStr; angle <= angleEnd ;)
{

if (first)
{
::MoveToEx(myDC, px, py, NULL);
first = false;
}
else
::LineTo(myDC, px, py);

angle += step;
if (angle > angleEnd && !close)
{
angle = angleEnd;
close = true;
}
}
}

step is the resolution you want to have drawing your's arc

Hope this help.

Quote:

> Hello,
> I want to draw a circle in borland c++ builder 6.0 on TImage object. I

have got the information like center of the circle and radius. i couldn't
Image to clear the drawn object. I have tried refresh and repaint but
couldn't succeed .

> abhimanyu

### How to draw a circle on Timage object with given center and radius

Hi Abhimanyu,
The Canvas.Ellipse routine can draw the circle for you.

To calculate the rectangle given a center and radius, try this algorithm.

Now draw the ellipse with this TRect.

Regards,
Ananth B.

Quote:

> Hello,
> I want to draw a circle in borland c++ builder 6.0 on TImage object.

[snip]

### How to draw a circle on Timage object with given center and radius

Draws the ellipse defined by a bounding rectangle on the canvas.

void __fastcall Ellipse(int X1, int Y1, int X2, int Y2);

part of the TCanvas.
X1, Y1 is the upper left,top corner of the Boxed area of the circle,
X2, Y2 is the lower,right of the Boxed area of the circle.
X1 and X2 would be the left,Right for the target of 0/180 degree axes.
Y1, Y2 is the Heght,Bottom of the 90/270 degree axes..
for example , lets assume you are going to draw a circle starting at 100,100
the lower, right X,Y factor would be  400,400;
100,100,400,400 .....
----
you can also draw your circle usnig SIN instead of a built in API call.
the trig functions work in Rads so that means you must think of a complete circle
as PI*2 = 6.28.....
if you were to make a loop from 0..6.28 in some frational steps you can thus
use the Sum in the SIn Function. which will give you tyhe -/+ 1/0 scales.
ect..

> Hello,
> I want to draw a circle in borland c++ builder 6.0 on TImage object. I have got the information like center of the circle and radius. i couldn't found any circle fuction in BCB. Please help me. also i want to refresh the Image to clear the drawn object. I have tried refresh and repaint but couldn't succeed .

> abhimanyu