Jump to content

Centre and radius of a circle passing through 3 points in a plane: Difference between revisions

Added XPL0 example.
(Added XPL0 example.)
 
Line 702:
Check radius as the distance between the centre and the first point:
14.708623978334
</pre>
 
=={{header|XPL0}}==
{{trans|C++}}
<syntaxhighlight lang "XPL0">proc FindCircle(X1, Y1, X2, Y2, X3, Y3);
real X1, Y1, X2, Y2, X3, Y3;
real X12, X13, Y12, Y13, Y31, Y21, X31, X21,
SX13, SY13, SX21, SY21,
F, G, C, H, K, R;
[
X12:= X1 - X2;
X13:= X1 - X3;
Y12:= Y1 - Y2;
Y13:= Y1 - Y3;
Y31:= Y3 - Y1;
Y21:= Y2 - Y1;
X31:= X3 - X1;
X21:= X2 - X1;
SX13:= sq(X1) - sq(X3);
SY13:= sq(Y1) - sq(Y3);
SX21:= sq(X2) - sq(X1);
SY21:= sq(Y2) - sq(Y1);
F:= (SX13*X12 + SY13*X12 + SX21*X13 + SY21*X13) / (2.*(Y31*X12 - Y21*X13));
G:= (SX13*Y12 + SY13*Y12 + SX21*Y13 + SY21*Y13) / (2.*(X31*Y12 - X21*Y13));
C:= -sq(X1) - sq(Y1) - 2.*G*X1 - 2.*F*Y1;
H:= -G;
K:= -F;
R:= sqrt(H*H + K*K - C);
 
Text(0, "Centre is at "); RlOut(0, H); Text(0, ", "); RlOut(0, K); CrLf(0);
Text(0, "Radius is "); RlOut(0, R);
];
FindCircle(22.83, 2.07, 14.39, 30.24, 33.65, 17.31)
</syntaxhighlight>
{{out}}
<pre>
Centre is at 18.97852, 16.26541
Radius is 14.70862
</pre>
295

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.