This answer quotes ChatGPT
Suppose the coordinate of point A is(xA, yA), the coordinate of point B is(xB, yB), the length of AC is c, the length of BC is d, and the coordinate of point C is(xC, yC).
according to the Pythagorean theorem, the AC ^ 2 =(xC - xA) ^ 2 +(yC - yA) ^ 2, BC ^ 2 =(xC - xB) ^ 2 +(yC - yB) ^ 2.
Transpose xC^2 and yC^2 in AC^2 and BC^2 to give the following two equations:
xC^2 - 2 xC xA + xA^2 + yC^2 - 2 yC yA + yA^2 = c^2
xC^2 - 2 xC xB + xB^2 + yC^2 - 2 yC yB + yB^2 = d^2
Subtract xC^2 and yC^2 from both equations to get:
-2 xC xA + xA^2 - 2 xC xB + xB^2 - 2 yC yA + yA^2 - 2 yC yB + yB^2 = c^2 - d^2
The above equation is simplified to give the following two equations:
xC = [(c^2 - d^2) +(xB^2 - xA^2) +(yB^2 - yA^2)] /(2(xB - xA))
yC = [(c^2 - d^2) +(yB^2 - yA^2) + 2 xC(xA - xB)] /(2(yB - yA))
Therefore, the coordinates of point C can be calculated by the above formula.
#include
#include
struct point {
float x, y;
};
struct point calculate_C(struct point A, struct point B, float AC, float BC) {
struct point C;
float AB = sqrt(pow(B.x - A.x, 2) + pow(B.y - A.y, 2));
float cosA = (pow(AC, 2) + pow(AB, 2) - pow(BC, 2)) / (2 * AC * AB);
float sinA = sqrt(1 - pow(cosA, 2));
C.x = A.x + AC * (B.x - A.x) / AB;
C.y = A.y + AC * (B.y - A.y) / AB;
float dx = (C.x - A.x) * cosA - (C.y - A.y) * sinA + A.x;
float dy = (C.x - A.x) * sinA + (C.y - A.y) * cosA + A.y;
C.x = dx;
C.y = dy;
return C;
}
int main() {
struct point A = {2, 3};
struct point B = {10, 5};
float AC = 8.0623;
float BC = 10.0499;
struct point C = calculate_C(A, B, AC, BC);
printf("C = (%.2f, %.2f)\n", C.x, C.y);
return 0;
}
A struct point structure is used here to represent the coordinate points, and the calculate_C function is used to calculate the coordinates of point C. In the main function, coordinates A and B as well as the values of side lengths AC and BC can be set. In addition, calculate_C function can be called to calculate the coordinates of point C and print it out.