I have to say that if you follow the link you provided, this would help keep the variable names the same. We could better understand the algorithm by seeing x1, y1, x2, y2, x3, y3 instead of p1, p2, p3, p4, alpha and beta. In fact, I donโt see much in your algorithm that matches the link. I'm not trying to be as harsh as comments (and if you are worried about switching float to double, that would be a good example for typedef), but debugging algorithms are easiest when you don't need to convert variable names.
I would recommend just using what they give you for h and k in the link, which is done by calculating the determinants of 3x3 matrices. You can find many links for this.
I would perform two functions:
float calculateH(float x1, float y1, float x2, float y2, float x3, float y3) { float numerator = (x2*x2+y2*y2)*y3 - (x3*x3+y3*y3)*y2 - ((x1*x1+y1*y1)*y3 - (x3*x3+y3*y3)*y1) + (x1*x1+y1*y1)*y2 - (x2*x2+y2*y2)*y1; float denominator = (x2*y3-x3*y2) - (x1*y3-x3*y1) + (x1*y2-x2*y1); denominator *= 2; return numerator / denominator; } float calculateK(float x1, float y1, float x2, float y2, float x3, float y3) { float numerator = x2*(x3*x3+y3*y3) - x3*(x2*x2+y2*y2) - (x1*(x3*x3+y3*y3) - x3*(x1*x1+y1*y1)) + x1*(x2*x2+y2*y2) - x2*(x1*x1+y1*y1); float denominator = (x2*y3-x3*y2) - (x1*y3-x3*y1) + (x1*y2-x2*y1); denominator *= 2; return numerator / denominator; }
Then your is_formCircle will be simple:
float is_formCircle(float x1, float y1, float x2, float y2, float x3, float y3) { float h = calculateH(x1, y1, x2, y2, x3, y3); float k = calculateK(x1, y1, x2, y2, x3, y3); printf("x=%fy=%f\n",h,k); }
There are many ways to optimize this, and there is a chance that I have sealed any of the determinant calculations, but it should make you go.