2005. augusztus 3., szerda

How to generate a circle through three points


Problem/Question/Abstract:

How to generate a circle through three points

Answer:

Let the three given points be a, b, c. Use _0 and _1 to represent x and y coordinates. The coordinates of the center p = (p_0,p_1) of the circle determined by a, b, and c are:



A = b_0 - a_0;
B = b_1 - a_1;
C = c_0 - a_0;
D = c_1 - a_1;

E = A * (a_0 + b_0) + B * (a_1 + b_1);
F = C * (a_0 + c_0) + D * (a_1 + c_1);

G = 2.0 * (A * (c_1 - b_1) - B * (c_0 - b_0));

p_0 = (D * E - B * F) / G;
p_1 = (A * F - C * E) / G;



If G is zero then the three points are collinear and no finite-radius circle through them exists. Otherwise, the radius of the circle is:



r^2 = (a_0 - p_0)^2 + (a_1 - p_1)^2

Nincsenek megjegyzések:

Megjegyzés küldése