char cInter1_x[20];
char cInter1_y[20];
char cInter2_x[20];
char cInter2_y[20];
String sInter1_x;
String sInter1_y;
String sInter2_x;
String sInter2_y;
float a, dx, dy, d, h, rx, ry;
float point2_x, point2_y;
// dx and dy are the vertical and horizontal distances between
// the circle centers.
dx = x1 - x0;
dy = y1 - y0;
// Determine the straight-line distance between the centers.
d = sqrt((dy*dy) + (dx*dx));
// Check for solvability.
if (d > (r0 + r1))
{
// no solution. circles do not intersect.
return false;
}
if (d < abs(r0 - r1))
{
// no solution. one circle is contained in the other
return false;
}
// 'point 2' is the point where the line through the circle
//intersection points crosses the line between the circle
//centers.
// Determine the distance from point 0 to point 2.
a = ((r0*r0) - (r1*r1) + (d*d)) / (2.0 * d) ;
// Determine the coordinates of point 2.
point2_x = x0 + (dx * a/d);
point2_y = y0 + (dy * a/d);
// Determine the distance from point 2 to either of the
// intersection points.
h = sqrt((r0*r0) - (a*a));
// Now determine the offsets of the intersection points from
// point 2.
rx = -dy * (h/d);
ry = dx * (h/d);
// Determine the absolute intersection points.
float intersectionPoint1_x = point2_x + rx;
float intersectionPoint2_x = point2_x - rx;
float intersectionPoint1_y = point2_y + ry;
float intersectionPoint2_y = point2_y - ry;
sInter1_x = floatToChar(intersectionPoint1_x, cInter1_x);
sInter1_y = floatToChar(intersectionPoint1_y, cInter1_y);
sInter2_x = floatToChar(intersectionPoint2_x, cInter2_x);
sInter2_y = floatToChar(intersectionPoint2_y, cInter2_y);
println("INTERSECTION Circle1 AND Circle2: " + "(" + sInter1_x + "," + sInter1_y + ")" + " AND (" + sInter2_x + "," + sInter2_y + ")");
String floatToChar(float inter, char temp[20]) {
dtostrf(inter,2,2,temp);
String answer = String(temp);
return answer;
}
Bakr:
Because my data will keep be printed second after second and I need everything to be organized.
That's no reason to use Strings. You could do the same with cleverly placed used of Serial.print vs Serial.println or you could use the sprintf method noted above.
Organized data:
Serial.print("A = ");
Serial.print(A);
Serial.print(" B = ");
Serial.print(B);
Serial.print(" C = ");
Serial.println(C);
Get's you (with hypthetical values for the variables):
A = 3 B = 4 C = 10
A = 5 B = 6 C = 12
A = 5 B = 2 C = 11
A = 5 B = 7 C = 14
I don't know how it gets more organized than that.
Delta_G:
That's no reason to use Strings. You could do the same with cleverly placed used of Serial.print vs Serial.println or you could use the sprintf method noted above.
Organized data:
Serial.print("A = ");
Serial.print(A);
Serial.print(" B = ");
Serial.print(B);
Serial.print(" C = ");
Serial.println(C);
Get's you (with hypthetical values for the variables):
A = 3 B = 4 C = 10
A = 5 B = 6 C = 12
A = 5 B = 2 C = 11
A = 5 B = 7 C = 14
I don't know how it gets more organized than that.
But again we come to the problem of Serial.println()
I can't see where "println" is defined, but in C/C++, the correct way to concatenate constant strings is NOT to use '+'
Thus char string [] = "The " "quick " "brown " "fox"; is equivalent to char string [] = "The quick brown fox";