c - 基于 C 中坐标的三角形边

标签 c

所以这段代码应该计算ab边的大小以及三角形的高度,我太笨了,没有意识到哪里出了问题,有人可以帮我找到错误吗?感谢帮助。

#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/

相关文章:

c - Valgrind/Helgrind 错误地将 TTAS 模式报告为种族

c - 在 Linux 上递归搜索所有子目录中的文件

Python struct.unpack 从 4 字节到 char

c - 为什么 GCC 不优化掉函数序言和结尾 (push ebp; mov ebp, esp; ...; pop ebp)

c - Swift调用C调用Swift?

c - 在多个线程中独立运行 Boehm GC

c - 我刚刚开始学习C : Can someone explain what the pointers and typecasting are doing in this code?

Python Ctypes 传入指针并返回结构

c - 我应该在 select() EBADF 上断言失败吗?

c - 从 C 中的 main 返回时,正在运行的线程会发生什么?