C# 通过坐标计算角度
答案:2 悬赏:20
解决时间 2021-04-27 20:48
- 提问者网友:心裂
- 2021-04-27 12:23
例如在panle中,鼠标在其中任意位置点击2次,获得2组Point坐标数据,通过此2点画条直线,计算此直线相对于水平面(也就是x轴)的角度,只求能告诉我如何计算角度,公式是什么,直角坐标系的坐标和C#的坐标系不太一样,这块怎么处理?在线等,谢谢
最佳答案
- 二级知识专家网友:狠傷凤凰
- 2021-04-27 12:59
double angleOfLine = Math.Atan2((Y2 - Y1), (X2 - X2)) * 180 / Math.PI
全部回答
- 1楼网友:摧毁过往
- 2021-04-27 13:31
try
{
//参数赋值
double ss1 = 0.00000001, ss2 = 1000000,we=7.2921151467*ss1*1000;
double pi = 3.1415926535;
string[] str = textbox2.text.trim().split(' ');
double[,] a = new double[7, 4];
int k = 0;
for (int i = 0; i < 7; i++)
{
for (int j = 0; j < 4; j++)
{
a[i, j] = convert.todouble(str[k]);
k++;
}
}
//规划时刻计算
int[] dinmth = new int[12];
double year, month, day, hour, minute, second, dayofy, ttlday, dayofw, gpstime, tk;
int weekno;
dinmth[0] = 31; dinmth[1] = 28; dinmth[2] = 31;
dinmth[3] = 30; dinmth[4] = 31; dinmth[5] = 30;
dinmth[6] = 31; dinmth[7] = 31; dinmth[8] = 30;
dinmth[9] = 31; dinmth[10] = 30; dinmth[11] = 31;
year = convert.todouble(textbox21.text);
month = convert.todouble(textbox22.text);
day = convert.todouble(textbox23.text);
hour = convert.todouble(textbox24.text);
minute = convert.todouble(textbox25.text);
second = convert.todouble(textbox26.text);
if (month == 1)
{
dayofy = day;
}
else
{
dayofy = 0;
for (int i = 0; i < 12; i++)
{
dayofy += dinmth[i];
if (i == 1)
{
if (year % 4 == 0 && year % 100 != 0 || year % 400 == 0)
dayofy += 1;
}
}
dayofy += day;
}
ttlday = 360;
for (int yr = 1981; yr < year; yr++)
{
ttlday += 365;
if (yr % 4 == 0 && yr % 100 != 0 || yr % 400 == 0)
{
ttlday += 1;
}
}
ttlday += dayofy;
weekno = (int)(ttlday / 7);
dayofw = ttlday - 7 * weekno;
gpstime = hour * 3600 + minute * 60 + second + dayofw * 86400;
tk = gpstime - a[3, 0] * ss2;
if (tk > 302400)
{
tk -= 604800;
}
else if(tk<-302400)
{
tk += 602400;
}
app.value1 = tk.tostring("e2");
//平均角速度计算
double n0, n;
n0 = (math.sqrt(3986004.418) / math.pow(a[2, 3], 3)) * ss1;
n = n0 + a[1, 2] * ss1;
app.value2 = n.tostring("e2");
//平近点角计算
double m0, mk;
m0 = a[1, 3];
mk = m0 * 10 + n * tk;
if (math.abs(mk) > 2 * pi)
{
int w1 = (int)(mk / (2 * pi));
mk = mk - 2 * pi * w1;
}
app.value3 = mk.tostring("e2");
//偏近点角计算
double ek, e0;
ek = mk;
do
{
e0 = ek;
ek = mk + a[2, 1] * 0.1 * math.sin(e0);
} while (math.abs(ek - e0) > 0.00000001);
app.value4 = ek.tostring("e2");
//真近点角
double angle1, angle2, vk;
angle1 = math.sqrt(1 - math.pow(a[2, 1] * 0.1, 2)) * math.sin(ek);
angle2 = math.cos(ek) - a[2, 1] * 0.1;
vk = math.atan(math.abs(angle1 / angle2));
if (angle1 >= 0 && angle2 <= 0)
{
vk = pi - vk;
}
else if (angle1 <= 0 && angle2 <=0)
{
vk = pi + vk;
}
else
{
vk = 2 * pi - vk;
}
app.value5 = vk.tostring("e");
//升交角距
double qk;
qk = vk + a[4, 2] * 10;
if (math.abs(qk) > 2 * pi)
{
int w2 = (int)(qk / (2 * pi));
qk = qk - 2 * pi * w2;
}
app.value6 = qk.tostring("e");
//升交角距改正,轨道向径改正,轨道倾角改正计算
double fu, fr, fi;
fu = a[2, 0] * ss1 * 1000 * math.cos(2 * qk) + a[2, 2] * ss1 * 1000 * math.sin(2 * qk);
fr = a[4, 1] * 1000 * math.cos(2 * qk) + a[1, 1] * 100 * math.sin(2 * qk);
fi = a[3, 1] * ss1 * 100 * math.cos(2 * qk) + a[3, 3] * ss1 * 10 * math.sin(2 * qk);
app.value7 = fu.tostring("e");
app.value8 = fr.tostring("e");
app.value9 = fi.tostring("e");
//改正后升交角距、轨道向径、轨道倾角计算
double uk, rk, ik;
uk = qk + fu;
rk = math.pow(a[2, 3] * ss2 * 0.01, 2) * (1 - a[2, 1] * 0.1 * math.cos(ek)) + fr;
ik = a[4, 0] + fi + a[5, 0] * ss1 * 0.1 * tk;
app.value10 = uk.tostring("e");
app.value11 = rk.tostring("e");
app.value12 = ik.tostring("e");
//升交点轨道直角坐标系坐标计算
double xk, yk;
xk = rk * math.cos(uk);
yk = rk * math.sin(uk);
app.value13 = xk.tostring("e");
app.value14 = yk.tostring("e");
//升交点经度计算
double n;
int w3;
n = a[3, 2] * 10 + (a[4, 3] * ss1 - we) * tk - we * a[3, 0] * ss2;
if (math.abs(n) > 2 * pi)
{
w3 =(int)(n / (2 * pi));
n = n - 2 * pi * w3;
}
app.value15 =n.tostring("e");
//地固坐标系下卫星空间直角坐标计算,ik为ik
double x, y, z;
x = xk * math.cos(n) - yk * math.cos(ik) * math.sin(n);
y = xk * math.sin(n) + yk * math.cos(ik) * math.cos(n);
z = yk * math.sin(ik);
app.value16 = x.tostring("e");
app.value17 = y.tostring("e");
app.value18 = z.tostring("e");
new form2().showdialog();
}
catch
{
messagebox.show("请输入卫星时刻或又一次加载卫星参数导致出错");
return;
}
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息!
大家都在看
推荐信息