三角函数。试图在 C# 中创建一个特定的公式
Trigonometry. trying to create a specific formula in C#
我正在尝试用 C# 创建一个公式。专门针对三角形计算
我没有得到正确的结果,似乎无法弄清楚如何得到
公式=c=√(b^2+a^2-2·b·a·cos(C)
公式图片=Formula
公式中,objective是求小c。
当你知道大C小a小b时
这是我的代码
public double returnC(double C, double a, double b)
{
double number2 = 2;
double potentiationfora = Math.Pow(a, 2);
double potentiationforb = Math.Pow(b, 2);
double CalculationPart1 = number2 * b;
double CalculationPart2 = a * Math.Cos(C);
double CalculationPart3 = CalculationPart1 * CalculationPart2;
double PotensCombiner = potentiationfora + potentiationforb;
double CalculationPart4 = PotensCombiner - CalculationPart3;
double cResult = Math.Sqrt(CalculationPart4);
return cResult;
}
CalculationPart2 应该得到 6.427876 但我得到 9.649660
Math.Cos(50)?为什么不是C?另请注意,Math.Cos 采用以弧度为单位的角度。
还有 double cResult = Math.Pow(1, CalculationPart4);这似乎不对,请使用 Math.Sqrt
public double returnC(double C, double a, double b)
{
double a2 = Math.Pow(a, 2);
double b2 = Math.Pow(b, 2);
double _2abcosc = 2 * a * b * Math.Cos(C);
// if c is a degree then
//double _2abcosc = 2 * a * b * Math.Cos(C*Math.PI/180);
return Math.Sqrt( a2 + b2 - _2abcosc);
}
var 结果 = Math.Sqrt((Math.Pow(b, 2) + Math.Pow(a, 2)) - (2 * b * a * Math.Cos (C)));
我正在尝试用 C# 创建一个公式。专门针对三角形计算
我没有得到正确的结果,似乎无法弄清楚如何得到
公式=c=√(b^2+a^2-2·b·a·cos(C)
公式图片=Formula
公式中,objective是求小c。
当你知道大C小a小b时
这是我的代码
public double returnC(double C, double a, double b)
{
double number2 = 2;
double potentiationfora = Math.Pow(a, 2);
double potentiationforb = Math.Pow(b, 2);
double CalculationPart1 = number2 * b;
double CalculationPart2 = a * Math.Cos(C);
double CalculationPart3 = CalculationPart1 * CalculationPart2;
double PotensCombiner = potentiationfora + potentiationforb;
double CalculationPart4 = PotensCombiner - CalculationPart3;
double cResult = Math.Sqrt(CalculationPart4);
return cResult;
}
CalculationPart2 应该得到 6.427876 但我得到 9.649660
Math.Cos(50)?为什么不是C?另请注意,Math.Cos 采用以弧度为单位的角度。 还有 double cResult = Math.Pow(1, CalculationPart4);这似乎不对,请使用 Math.Sqrt
public double returnC(double C, double a, double b)
{
double a2 = Math.Pow(a, 2);
double b2 = Math.Pow(b, 2);
double _2abcosc = 2 * a * b * Math.Cos(C);
// if c is a degree then
//double _2abcosc = 2 * a * b * Math.Cos(C*Math.PI/180);
return Math.Sqrt( a2 + b2 - _2abcosc);
}
var 结果 = Math.Sqrt((Math.Pow(b, 2) + Math.Pow(a, 2)) - (2 * b * a * Math.Cos (C)));