所以这段代码应该计算a和b边的大小以及三角形的高度,我太笨了,没有意识到哪里出了问题,有人可以帮我找到错误吗?感谢帮助。
#include <stdio.h>
#include <math.h>
float distance(float, float, float, float);
int main()
{
float a, b, c, d;
float aX, aY, alfa;
float bX, bY, beta;
scanf("%f %f %f" , &aX, &aY, &alfa);
scanf("%f %f %f", &bX, &bY, &beta);
distance(aX, aY, bX, bY);
float gamma = 180 - alfa - beta;
c = distance(aX, aY, bX, bY);
b = ((c/sin(gamma)) * sin(beta));
a = ((c/sin(gamma)) * sin(alfa));
d = (sin(alfa))*c;
printf("Side a:%.2f\n Side b:%.2f\n Side c:%.2f Height:%.2f\n", a, b, c, d);
return 0;
}
float distance(float x1, float y1, float x2, float y2)
{
float dx = x2 - x1;
float dy = y2 - y1;
return sqrt(dx*dx + dy*dy);
}
最佳答案
问题是您使用度数而不是弧度。三角函数必须应用于以弧度测量的值。
关于c - 基于 C 中坐标的三角形边,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47113512/