TCanvas.Arc

Hello, can somebody explain how the Canvas.Arc function works (I'm newbie)
THX
zerotwoAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
nnbbb09Connect With a Mentor Commented:
Hello,

The Arc procedure can be a bit difficult to use, but I will try and explain how.

1. The first thing to do is draw a rectangle on a piece of paper that would mark the boundaries of your ENTIRE ellipse if it were fully drawn on your canvas and mark out its top-left, top-right, bottom-left and bottom-right co-ordinates. From this rectangle you will need the top left and bottom right co-ordinates. These will become the first four parameters used in the arc procedure.

2. Once you've drawn the boundary rectangle you need to identify the starting point of your arc on the boundary rectangle. Remember that the arc moves anti-clockwise. From this you will need the x an y co-ordinates

3. Then identify the stopping point of your arc on the boundary rectangle. Remember that the arc moves anti-clockwise. From this you will need the x an y co-ordinates.

4. The x and y co-ordinates from steps 2 and 3 make up the last four parameters used in the arc procedure.


For example if my boundary rectangle was 200 pixels wide and 100 pixels high it's parameters would be 0,0,200,100 and if I wanted to draw a quarter arc in the top left of the rectangle then it would start at co-ordinate 100,0 and end at co-ordinate 0,50 (ie: both these co-ordinates intersect the boundary rectangle) so the final Arc parameters would be Canvas.Arc(0,0,200,100,100,0,0,50)

Likewise if I wanted to draw a semi-circle type arc across the top of the rectangle then the starting position of the arc would change to 200,50 and the end co-ordinate would stay as 0,50 giving you an Arc Parameter of (0,0,200,100,200,50,0,50)

Hope this helps.

Jo
1
 
Mohammed NasmanSoftware DeveloperCommented:
Hello

  from delphi help

TCanvas.Arc
 
 TCanvas        See also          Example
 
 Draws an arc on the image along the perimeter of the ellipse bounded by the specified rectangle.  
 
 procedure  Arc(X1, Y1, X2, Y2, X3, Y3, X4, Y4:  Integer );
 
 Description
 
 Use Arc to draw an elliptically curved line with the current Pen. The arc traverses the perimeter of an ellipse that is  bounded by the points (X1,Y1) and (X2,Y2). The arc is drawn following the perimeter of the ellipse,  counterclockwise, from the starting point to the ending point. The starting point is defined by the intersection of the  ellipse and a line defined by the center of the ellipse and (X3,Y3). The ending point is defined by the intersection of  the ellipse and a line defined by the center of the ellipse and (X4, Y4).
 
 Note:        On Windows 95, the sums X1 + X2 and Y1 + Y2 cannot exceed 32768. Also, the sum X1 + X2 + Y1 + Y2  cannot exceed 32768.
 
 On NT, the drawing direction can be changed to clockwise using the Windows API call SetArcDirection.
 
 
and this example to draw arc on the form

procedure TForm1.Button1Click(Sender: TObject);
  var
    R: TRect;
  begin
    R := GetClientRect;   {Gets the boundaries of the  current window}
    Canvas.Arc(R.Left, R.Top, R.Right, R.Bottom, R.Right,  R.Top, R.Left, R.Top);
  end ;

Mohammed


0
 
robert_marquardtCommented:
I used the function myself and it is horrible. Best use Win32 function AngleArc. It is much more precise.
Simply hand in the DC of the Canvas and it will work.
Only ensure that the Canvas is initialized by painting to it.
Arc has problems drawing small angles which amount to less than one pixel. It draws a full circle then.
0
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
zerotwoAuthor Commented:
Hi, can you tell me how to draw an arc that starts at 0,0 and goes to 500,400! The arc should "turn" round the point 0,400
THX  
0
 
sburckCommented:
I think that by your second question, you might be looking to do a Bezier curve rather than an arc.  To experiment with one, try this:

Make a form with 4 trackbars (keep them on the right side of the form, so they stay out of the way).  Make Trackbar1 and Trackbar 2 go from Min 0 to Max 500, and Trackbar3 and Trackbar 4 go from Min 0 to Max 400.  The first two are the x coordinates of your control points, and the second are the y coordinates.

Add this code:

var
        ta : array[0..4] of TPoint;

procedure TForm1.FormShow(Sender: TObject);
begin
        // Select a starting position....
        TrackBar1.Position := 10;
        TrackBar2.Position := 100;
        TrackBar3.Position := 100;
        TrackBar4.Position := 300;
        TrackBar1Change(Sender);
end;

procedure TForm1.TrackBar1Change(Sender: TObject);
begin
        Form1.Canvas.Pen.Color := Form1.Color;
        Form1.Canvas.PolyBezier(Slice(ta,4));
        ta[0].x := 0;
        ta[0].y := 0;
        ta[1].x := TrackBar1.Position;
        ta[1].y := TrackBar3.Position;
        ta[2].x := TrackBar2.Position;
        ta[2].y := TrackBar4.Position;
        ta[3].x := 500;
        ta[3].y := 400;
        Form1.Canvas.Pen.Color := clBlack;
        Form1.Canvas.PolyBezier(Slice(ta,4));
end;

Now, you can work with the values you want your final curve to have.
0
 
zerotwoAuthor Commented:
Hi sburck, thanks for your comment, but actually, I need to draw more then just one arc, and if I do it the way you suggest, it's much to complicated!
I just don't really get why you can't do like this canvas.arc(0,0,500,400,500,400,0,0). The arc just doesn't start at 0,0 and ends at 500,400!
Thats actually why I asked if somebody can explain how to do this
THX
0
 
sburckCommented:
I don't mean to actually draw it using the Trackbars, but if you've never used a Bezier before, it gives you a good idea of the way the control points work.  Drawing curves with fixed start/endpoints is MUCH easier with Bezier curves than arcs - with arcs, you have to calculate intersection points between ellipses and rectangles; with a Bezier, you just state the endpoints, and then pull the curve in the diretion you want with the control points.  A fixed arc like you wanted would be something like:

        ta[0].x := 0;
        ta[0].y := 0;
        ta[1].x := 0;
        ta[1].y := 400;
        ta[2].x := 0;
        ta[2].y := 400;
        ta[3].x := 500;
        ta[3].y := 400;
        Form1.Canvas.PolyBezier(Slice(ta,4));

Note that ta[0] is one endpoint, ta[3] is the other, and the two middle points pull the curve in their direction to give the effect you want.
0
 
zerotwoAuthor Commented:
I'm sorry, but can't accept anything as your answer, because I really need to know how I can use the Canva.Arc procedure
0
 
zerotwoAuthor Commented:
Sburck, you gave me a lot of good code, that's why I put out 20 points with grade A for you...go fetch them!
0
 
zerotwoAuthor Commented:
You know why I didn't understand the Canvas.Arc procedure? Because if the width of the form is 500 and hight 400 you cannot see the whole arc if you write Canvas.Arc(0,0,500,400,0,0,250,400) because pixels aren't equal to Form.width! Thanks for good explanation
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.