已知三边的边长 怎么用余弦定理求角度啊

meinu1011 2016-12-30 09:38:15
这样做为什么能运行 却求值时报错啊
...
double α = DEG(Math.Acos((b*b+c*c-a*a)/2*b*c));
static public double DEG(double ang)
{
int fuhao = (int)(ang / Math.Abs(ang));
ang = Math.Abs(ang);
int d = (int)ang;
int m = ((int)(ang * 100)) - d * 100;
double s = ang * 10000 - m * 100 - d * 10000;
return ((d + m / 60.0 + s / 3600.0) * fuhao) / 180.0 * Math.PI;
}
...

...全文
1103 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
EnForGrass 2016-12-30
  • 打赏
  • 举报
回复
C# 有Math.Acos方法,
xuzuning 2016-12-30
  • 打赏
  • 举报
回复
            double a = 3, b = 4, c = 5;
//double α = DEG(Math.Acos((b * b + c * c - a * a) / (2 * b * c)));
double α = Math.Acos((b * b + c * c - a * a) /( 2 * b * c));
Console.WriteLine(α);
Console.WriteLine(α/Math.PI*180);

你的 DEG 方法很是奇怪,不是其意
夏天的枫 2016-12-30
  • 打赏
  • 举报
回复
meinu1011 2016-12-30
  • 打赏
  • 举报
回复
using System;
using System.Drawing;
using System.Windows.Forms;

namespace Daoxian
{
/// <summary>
/// Description of Form4.
/// </summary>
public partial class Form4 : Form
{
public Form4()
{
//
// The InitializeComponent() call is required for Windows Forms designer support.
//
InitializeComponent();

//
// TODO: Add constructor code after the InitializeComponent() call.
//
}
void Button1Click(object sender, EventArgs e)
{
double Ax = double.Parse(textBox1.Text);
double Ay = double.Parse(textBox2.Text);
double Bx = double.Parse(textBox3.Text);
double By = double.Parse(textBox4.Text);
double b = double.Parse(textBox5.Text);
double a = double.Parse(textBox6.Text);
double c = 距离(Ax, Ay, Bx, By);
double α = DEG(Math.Acos((b*b+c*c-a*a)/2*b*c));
double β = DEG(Math.Acos((a*a+c*c-b*b)/2*a*c));
c = c / Math.Sin(Math.PI - α - β) * Math.Sin(β);
double a0 = 方位角(Ax, Ay, Bx, By);
//计算A到J的坐标方位角
a0 -= α;
double Jx = Ax + c * Math.Cos(a0);
double Jy = Ay + c* Math.Sin(a0);
textBox7.Text = Jx.ToString()+System.Environment.NewLine + Jy.ToString();
}
static public double DEG(double ang)
{
int fuhao = (int)(ang / Math.Abs(ang));
ang = Math.Abs(ang);
int d = (int)ang;
int m = ((int)(ang * 100)) - d * 100;
double s = ang * 10000 - m * 100 - d * 10000;
return ((d + m / 60.0 + s / 3600.0) * fuhao) / 180.0 * Math.PI;
}
public static double 方位角(double x1, double y1, double x2, double y2)
{
double deltaX = x2 - x1;
double deltaY = y2 - y1;
double angle = Math.PI * 0.5;
if (Math.Abs(deltaX) > 0.000000001)
{
angle = Math.Atan2(deltaY, deltaX);
}
if (angle < 0)
{
angle += Math.PI;
}
if (deltaY < 0.0)
{
angle += Math.PI;
}
return angle;
}
//计算距离
public static double 距离(double x1, double y1, double x2, double y2)
{
return Math.Sqrt((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1));
}

}
}



大致是这样了 求大神帮我看看 就是想实现测量学中的测边交会

110,537

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧