<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=us-ascii">
<META name=GENERATOR content="MSHTML 8.00.6001.18928">
<STYLE></STYLE>
</HEAD>
<BODY bgColor=#ffffff>
<DIV dir=ltr align=left><SPAN class=629012809-18012011><FONT color=#800000
size=2 face=Verdana>Hi,</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=629012809-18012011><FONT color=#800000
size=2 face=Verdana></FONT></SPAN> </DIV>
<DIV dir=ltr align=left><SPAN class=629012809-18012011><FONT color=#800000
size=2 face=Verdana>Try this:</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=629012809-18012011><FONT color=#800000
size=2 face=Verdana></FONT></SPAN> </DIV>
<DIV dir=ltr align=left><SPAN class=629012809-18012011><FONT color=#800000
size=2 face=Verdana>procedure DrawCurve;<BR>var<BR> p1, p2, p3 :
TPoint;<BR> mp1, mp2 : TPoint; // chord midpoints<BR> c :
TPoint; // centre of circle<BR> rad : double; // radius of
circle<BR> r1, r2 : TPoint; // bounding rectangle (square)<BR> m1,
m2 : double; // slope of 2 chords<BR> x : double; // temp<BR>
angrot, angp1p2, angp2p3 : double;<BR>begin<BR>
SetPenAndBrush;<BR> DrawingCanvas.Pen.Style := psDash;
// only works if pen width = 1</FONT></SPAN></DIV>
<DIV><FONT color=#800000 size=2 face=Verdana></FONT> </DIV>
<DIV dir=ltr align=left><SPAN class=629012809-18012011><FONT color=#800000
size=2 face=Verdana> p1 :=
MakePoint(Data.tbEntity.FieldByName('Pt1x').AsFloat*Option.Factor,
Data.tbEntity.FieldByName('Pt1y').AsFloat*Option.Factor);<BR>
p2 := MakePoint(Data.tbEntity.FieldByName('Pt2x').AsFloat*Option.Factor,
Data.tbEntity.FieldByName('Pt2y').AsFloat*Option.Factor);<BR>
p3 := MakePoint(Data.tbEntity.FieldByName('Pt3x').AsFloat*Option.Factor,
Data.tbEntity.FieldByName('Pt3y').AsFloat*Option.Factor);<BR>
if ((p1.x = 0) and (p1.y = 0)) and ((p2.x = 0) and (p2.y = 0)) and ((p3.x = 0)
and (p3.y = 0)) then begin<BR>
exit;<BR> end;<BR> // sanity check - 3
different points<BR> if ((p1.x = p2.x) and (p1.y = p2.y)) or
((p1.x = p3.x) and (p1.y = p3.y)) or ((p3.x = p2.x) and (p3.y = p2.y)) then
begin<BR> ErrorMsg('All 3 points on a curve must
be different.');<BR>
Data.tbEntity.delete;<BR>
exit;<BR> end;</FONT></SPAN></DIV>
<DIV><FONT color=#800000 size=2 face=Verdana></FONT> </DIV>
<DIV dir=ltr align=left><SPAN class=629012809-18012011><FONT color=#800000
size=2 face=Verdana> // determine direction of curve
rotation<BR> try<BR> angp1p2 :=
math.arctan2((p2.y-p1.y), (p2.X-p1.X));<BR>
angp2p3 := math.arctan2((p3.y-p2.y),
(p3.X-p2.X));<BR> angrot := angp2p3 -
angp1p2;<BR> except<BR> angrot
:= 0; // straight line<BR> end;<BR> //
normalise the angle to between -pi..pi<BR> if angrot > pi
then<BR> angrot := angrot -
2*pi<BR> else if angrot < (-pi)
then<BR> angrot := angrot +
2*pi;<BR> if abs(angrot) < 0.05 then
begin<BR> // Cannot draw a curve through points in
a straight line.<BR> // draw a straight line
instead<BR> DrawingCanvas.MoveTo(p1.x,
p1.y);<BR> DrawingCanvas.LineTo(p3.x,
p3.y);<BR> exit;<BR>
end;<BR> if angrot > 0 then
begin<BR> // clockwise, so reverse start and end
points<BR> mp1.x :=
p1.x;<BR> mp1.y :=
p1.y;<BR> p1.x :=
p3.x;<BR> p1.y :=
p3.y;<BR> p3.x :=
mp1.x;<BR> p3.y := mp1.y;<BR>
end;</FONT></SPAN></DIV>
<DIV><FONT color=#800000 size=2 face=Verdana></FONT> </DIV>
<DIV dir=ltr align=left><SPAN class=629012809-18012011><FONT color=#800000
size=2 face=Verdana> // chord midpoint between p1 and
p2<BR> mp1.X := (p1.X + p2.X) div 2;<BR>
mp1.Y := (p1.Y + p2.Y) div 2;<BR> // chord midpoint between p2
and p3<BR> mp2.X := (p3.X + p2.X) div 2;<BR>
mp2.Y := (p3.Y + p2.Y) div 2;<BR> // slope of lines 1 and
2<BR> try<BR> m1 :=
1.0*(p2.y-p1.y)/(p2.x-p1.x);<BR>
except<BR> m1 := maxint; // for now
(vertical line)<BR> end;<BR>
try<BR> m2 :=
1.0*(p3.y-p2.y)/(p3.x-p2.x);<BR>
except<BR> m2 := maxint; // for now
(vertical line)<BR> end;<BR> // don't let
these slopes quite get to zero<BR> if (m1 < 0.01) and (m1
> 0) then m1 := 0.01;<BR> if (m1 > -0.01) and (m1 <
0) then m1 := -0.01;<BR> if (m2 < 0.01) and (m2 > 0)
then m2 := 0.01;<BR> if (m2 > -0.01) and (m2 < 0) then
m2 := -0.01;</FONT></SPAN></DIV>
<DIV><FONT color=#800000 size=2 face=Verdana></FONT> </DIV>
<DIV dir=ltr align=left><SPAN class=629012809-18012011><FONT color=#800000
size=2 face=Verdana> // slopes of perpendicular lines,
pointing to centre of circle<BR>
try<BR> m1 := -1/m1;<BR>
except<BR> m1 :=
maxint*iif(p3.Y<p2.Y,-1,1);<BR> end;<BR>
try<BR> m2 := -1/m2;<BR>
except<BR> m2 :=
maxint*iif(p1.Y<p2.Y,-1,1);<BR> end;<BR>
// x of circle centre<BR>
try<BR> x :=
(mp2.y-mp1.y-(m2*mp2.x)+(m1*mp1.x))/(m1-m2);<BR>
except<BR> // divide by zero, lines are parallel,
should never happen but just in case:<BR> // draw
a straight line instead<BR>
DrawingCanvas.MoveTo(p1.x, p1.y);<BR>
DrawingCanvas.LineTo(p3.x, p3.y);<BR>
exit;<BR> end;<BR> // y of circle
centre<BR> c.y :=
round(mp1.y+m1*(x-mp1.x));<BR> c.X :=
round(x);<BR> // radius<BR> rad :=
sqrt(sqr(p2.X-c.x)+sqr(p2.Y-c.Y));<BR> // bounding square and
circle<BR> r1.x := c.X - round(rad);<BR>
r2.x := c.X + round(rad);<BR> r1.y := c.y -
round(rad);<BR> r2.y := c.y + round(rad);</FONT></SPAN></DIV>
<DIV><FONT color=#800000 size=2 face=Verdana></FONT> </DIV>
<DIV dir=ltr align=left><SPAN class=629012809-18012011><FONT color=#800000
size=2 face=Verdana> DrawingCanvas.Arc(r1.X, r1.y, r2.x, r2.y,
p1.x,p1.y,p3.x,p3.y);</FONT></SPAN></DIV>
<DIV><FONT color=#800000 size=2 face=Verdana></FONT> </DIV>
<DIV><SPAN class=629012809-18012011><FONT color=#800000 size=2
face=Verdana>end;<BR></FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=629012809-18012011><FONT color=#800000
size=2 face=Verdana></FONT></SPAN> </DIV>
<DIV dir=ltr align=left><SPAN class=629012809-18012011><FONT color=#800000
size=2 face=Verdana>HTH,</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=629012809-18012011><FONT color=#800000
size=2 face=Verdana>Steve</FONT></SPAN></DIV><BR>
<BLOCKQUOTE
style="BORDER-LEFT: #800000 2px solid; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; MARGIN-RIGHT: 0px"
dir=ltr>
<DIV dir=ltr lang=en-us class=OutlookMessageHeader align=left>
<HR tabIndex=-1>
<FONT size=2 face=Tahoma><B>From:</B> Marshland Engineering
[mailto:marshland@marshland.co.nz] <BR><B>Sent:</B> Tuesday, 18 January 2011
9:03 p.m.<BR><B>To:</B> delphi@delphi.org.nz<BR><B>Subject:</B> [DUG]
Arc's<BR></FONT><BR></DIV>
<DIV></DIV>
<DIV><FONT size=2 face=Arial>Is there an easy way of drawing an arc
? I have center, start and end co-ordinates as XY. </FONT></DIV>
<DIV><FONT size=2 face=Arial></FONT> </DIV>
<DIV><FONT size=2 face=Arial>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. </FONT></DIV>
<DIV><FONT size=2 face=Arial></FONT> </DIV>
<DIV><FONT size=2 face=Arial>procedure Arc(X1, Y1, X2, Y2, X3, Y3, X4, Y4:
Integer);</FONT></DIV>
<DIV><FONT size=2 face=Arial></FONT> </DIV>
<DIV><FONT size=2 face=Arial>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).</FONT></DIV></BLOCKQUOTE></BODY></HTML>