Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

TCanvas.Arc

Posted on 2001-06-09
10
2,488 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:Mohammed Nasman
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
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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.

 
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
 
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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

839 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