zerotwo
asked on
TCanvas.Arc
Hello, can somebody explain how the Canvas.Arc function works (I'm newbie)
THX
THX
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.
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.
ASKER
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
THX
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(Sen der: TObject);
begin
Form1.Canvas.Pen.Color := Form1.Color;
Form1.Canvas.PolyBezier(Sl ice(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(Sl ice(ta,4)) ;
end;
Now, you can work with the values you want your final curve to have.
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(Sen
begin
Form1.Canvas.Pen.Color := Form1.Color;
Form1.Canvas.PolyBezier(Sl
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(Sl
end;
Now, you can work with the values you want your final curve to have.
ASKER
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
I just don't really get why you can't do like this canvas.arc(0,0,500,400,500
Thats actually why I asked if somebody can explain how to do this
THX
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(Sl ice(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.
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(Sl
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.
ASKER
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
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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!
ASKER
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
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
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