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

Post by abhimany » Fri, 30 May 2003 14:59:52


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 .
thanks in advance

abhimanyu

 
 
 

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

Post by PaoloItal » Fri, 30 May 2003 18:09:43


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))
float radius, step, resolution,angle;
int px, py;
bool first = true, close=false;
          if (radius)
          {
            step = rad2gr(resolution / radius);
            for (angle=angleStr; angle <= angleEnd ;)
            {
              px = x + radius * cos(gr2rad(angle));
              py = y + radius * sin(gr2rad(angle));

              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
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 .
Quote:> thanks in advance

> abhimanyu


 
 
 

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

Post by Ananth B » Fri, 30 May 2003 18:26:52


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

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

rect->Left = centerX - radius;
rect->Top = centerY - radius;
rect->Width = 2 * radius;
rect->Height = 2 * radius;

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

Post by Maynard Philbroo » Sun, 01 Jun 2003 13:09:26


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
 and your radius is for example 150 in pixels.
  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 .
> thanks in advance

> abhimanyu

 
 
 

1. Center of a circle given two points and the radius

Please Help!

I need to find the center of a circle given two points and the radius.
I know there are two possible answers to the equation depending on
what side the circle lies on from the two given points (This is OK). I
had already solved this in a program I wrote a year ago, but lost the
source code for the program and now I have to re-write it. Any help
will be appreciated.

Thanks in advance!

Scott

2. Calibrate Monitor

3. explorer: display a sphere given center and radius

4. Binaries group for Raytracing?

5. Circle with non-integer center and radius

6. ABuffer?

7. co-ordinates for a point on a circle given the angle and radius

8. Max into Lightscape

9. CIRCLE drawing large radius problem

10. drawing circles from center

11. Computing Center point of arc given only start point, end point , sweep angle direction draw