salut à tous
J'ai fait une fonction qui devrait me renvoyer les coordonnées de l'intersection de deux cercles mais celle-ci ne marche pas. Dites moi si vous voyez des erreurs dans mon code ou si vous avez une autre fonction à me proposer.
Merci d'avance
Voici le code :
deuxPositions intersectionCercles(int x1, int y1, float r1, int x2, int y2, float r2)
{
/* deuxpositions est une structure qui contient 4 flottants (float) */
deuxPositions dpX ;
int g1 = -x1;
int f1 = -y1;
float c1 = g1*g1 + f1*f1 - r1*r1;
int g2 = -x2;
int f2 = -y2;
float c2 = g2*g2 + f2*f2 - r2*r2;
int p = 2*(g1-g2);
int q = 2*(f1-f2);
float r = c1-c2;
int a = pow(q,2) + pow(p,2);
float b = 2*q*r - 2*p*g1*q + 2*f1*pow(p,2);
float c = pow(r,2) - 2*p*g1*r + pow(p,2)*c1;
float d = pow(b,2) - 4*a*c;
float sqrtd = sqrt(d);
float sy1 = (-b+sqrtd)/(2*a);
float sy2 = (-b-sqrtd)/(2*a);
float sx1 = (-q*sy1-r);
float sx2 ;
if(sx1 != 0) sx1/=p;
sx2 = (-q*sy2-r);
if(sx2!= 0) sx2/=p;
dpX.x1 = sx1 ;
dpX.x2 = sx2 ;
dpX.y1 = sy1 ;
dpX.y2 = sy2 ;
return dpX ;
}