Solved

TCanvas.Arc

Posted on 2001-06-09
10
2,363 Views
Last Modified: 2012-08-14
Hello, can somebody explain how the Canvas.Arc function works (I'm newbie)
THX
0
Comment
Question by:zerotwo
10 Comments
 
LVL 22

Expert Comment

by:mnasman
ID: 6172006
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
 
LVL 11

Expert Comment

by:robert_marquardt
ID: 6172756
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
 

Author Comment

by:zerotwo
ID: 6173254
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
 
LVL 3

Expert Comment

by:sburck
ID: 6174259
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
 

Author Comment

by:zerotwo
ID: 6179046
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
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 3

Expert Comment

by:sburck
ID: 6179600
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
 

Author Comment

by:zerotwo
ID: 6222535
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
 
LVL 3

Accepted Solution

by:
nnbbb09 earned 50 total points
ID: 6222798
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
0
 

Author Comment

by:zerotwo
ID: 6232972
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
 

Author Comment

by:zerotwo
ID: 6232992
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

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now