【问题标题】:Given the length of 3 sides of a triangle, find the missing angles [closed]给定三角形3条边的长度,找到缺失的角度[关闭]
【发布时间】:2021-10-10 18:15:16
【问题描述】:

我想计算给定 3 边长度的三角形的缺失角。 此代码为任何线距离的所有三个角度提供 -1.#IND00 输出值。

#include<stdio.h>
#include<math.h>

int main()
{
    float l1, l2, l3, a1, a2, a3;
    printf("Enter the line length of three lines of triangle: ");
    scanf("%f%f%f", &l1, &l2, &l3);
    a3 = acos( ((l1*l1)+(l2*l2)+(l3*l3))/(2*l1*l2) );
    a1 = asin( (l1*sin(a3))/l3 );
    a2 = acos(-1) - a1 - a3;
    printf("Three angles are: %f %f %f", a1, a2, a3);

    return 0;
}

【问题讨论】:

  • 错误的公式 (((l1*l1)+(l2*l2)+(l3*l3))/(2*l1*l2)) 生成的数字超出了acos() 的有效范围
  • 请注意,您应该检查所有值是否都是正数,并且没有两个边的总和小于第三边以验证输入。

标签: c algorithm geometry


【解决方案1】:

角度a3的公式是cos−1((l12+l22-l32) / (2l1l2)),不是 cos−1((l12+l2 2+l32) / (2l1l2)).

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-03-08
    • 1970-01-01
    • 2010-12-03
    • 2023-01-30
    • 1970-01-01
    • 2020-06-22
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多