Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I have to say, if you're following the link you listed, it would've helped to keep the variable names the same. We could understand the algorithm much better 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 the comments were (and if you're worried about switching float to double, that was a perfectly good case for a typedef), but debugging algorithms is easiest when you don't have to convert variable names.</p> <p>I would recommend simply using what they give you for h and k in the link, which is namely done by calculating determinants of 3x3 matrices. You can find lots of <a href="http://www.wikihow.com/Find-the-Determinant-of-a-3X3-Matrix" rel="nofollow">references</a> for that.</p> <p>I'd make two functions, as follows:</p> <pre><code>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; } </code></pre> <p>Then your is_formCircle would simply be:</p> <pre><code>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=%f y=%f\n",h,k); } </code></pre> <p>There are tons of ways to optimize this, and there's a chance I typoed any of the determinant calculations, but it should get you going.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload