[DUG] Arc's

Jolyon Smith jsmith at deltics.co.nz
Wed Jan 19 09:16:55 NZDT 2011


Drawing an arc is already easy, using the Canvas.Arc() method that you have
already identified.  J

 

You simply need to derive the values required to input to that method.  J

 

Given that you have the start/end points and it seems from the way you have
put it that these are known to be on the arc, all you are missing is the
bounding rectangle for the ellipse.

You have the center point, so if you know the axial dimensions of the
ellipse (width/height) then calculating the bounding rectangle is a simple
matter of:

 

  bound.Left   := center.x - (width div 2);

  bound.Top    := center.y - (height div 2);

  bound.Right  := center.x + (width div 2);

  bound.Bottom := center.y + (height div 2);

 

  Canvas.Arc( bound.Left, bound.Top, bound.Right, bound.Bottom, start.X,
start.Y, end.X, end.Y );

 

If the ellipse is (or could be) rotated then things are more complicated I
think.

 

I forget which is the default direction for arc drawing (clockwise or
counter-clockwise) but if you need to adjust that then I think you can
either simply swap your start/end points or explicitly set the arc direction
using the SetArcDirection() GDI call:

 

http://msdn.microsoft.com/en-us/library/dd162961(v=VS.85).aspx

 

If the start/end points are not actually ON the arc, then you will need to
calculate the intersection of the lines defined by those points w.r.t the
ellipse center.  This is basic trig tho, and any number of online sources
should provide the formulae for these calculations, should you need them.

 

 

From: delphi-bounces at delphi.org.nz [mailto:delphi-bounces at delphi.org.nz] On
Behalf Of Marshland Engineering
Sent: Tuesday, 18 January 2011 21:03
To: delphi at delphi.org.nz
Subject: [DUG] Arc's

 

Is there an easy way of drawing an arc ?  I have center, start and end
co-ordinates as XY. 

 

>From what I can see, I need to look at least 16 combinations to work out the
perimeter size depending in which quadrant the start and ends are in.  

 

procedure Arc(X1, Y1, X2, Y2, X3, Y3, X4, Y4: Integer);

 

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

DISCLAIMER:  This electronic message together with any attachments is
confidential.  If you are not the intended recipient, do not copy, disclose
or use the contents in any way.  Please also advise us by return e-mail that
you have received the message and then please destroy.  Carter Holt Harvey
is not responsible for any changes made to this message and / or any
attachments after sending by Carter Holt Harvey.  We use virus scanning
software but exclude all liability for viruses or anything similar in this
email or any attachment. 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://listserver.123.net.nz/pipermail/delphi/attachments/20110119/836f6be3/attachment.html 


More information about the Delphi mailing list