PseudoHuman
PseudoHuman

Reputation: 53

How to validate points to generate a circle equation

I want to know how to validate three points in a way that I could know if those points are correct to generate a circle. I'd like to know what the exceptions are so I can proceed to generate the circle equation.

For example, one exception is that you can't have three points in a straight line. P1(34,15) P2(67,15) P3(27,15)

As you can see they have the same value on 'Y', so you can't find the circle equation for those three points, there would be an error.

What other exceptions should I consider?

Upvotes: 1

Views: 72

Answers (1)

MBo
MBo

Reputation: 80287

Points cannot define circle if they are on the straight line, so you can check whether cross product of two vectors is zero

if CrossProduct(P2-P1, P3-P1) <> 0 then
  OK, circle is possible

in coordinates:
(P2.X - P1.X) * (P3.Y - P1.Y) - (P3.X - P1.X) * (P2.Y - P1.Y)

Note that coincidence of points also gives zero result, so you may separate these cases (it is possible to build infinite number of circles through two or single point)

Upvotes: 2

Related Questions