c语言笛卡尔坐标系两点坐标,计算笛卡尔坐标系或极坐标系中2个位置之间的夹角...

从经度和纬度,现在需要计算两个角度: 角度一个是地上0-180°的伺服高程。 角度二是步进电机(0-360°)相对于北极的旋转。

我已经有一些Java代码来尝试它,但它不会工作。我收到了奇怪的结果。例如:国际空间站位于我的正上方(400公里;经度和纬度相同),角度为:141.68°和135.28°

Ps:因此这是一个使用图书馆的学校项目不是一个选项...

public class Main {

public static void main(String[] args) {

//double issR = 6371 + 410.92521771305;

double issR = 6741;

double issLat = 58.190897;

double issLong = -30.585309;

//posR = height in km + earth radius

//posLat = position latitude in °(deg)

//posLong = position longitude in °(deg)

double posR = 6365.092;

double posLat = 58.190897;

double posLong = -30.585309;

//Convert to cartesian

double issX = issR * Math.sin(issLat) * Math.cos(issLong);

double issY = issR * Math.sin(issLat) * Math.sin(issLong);

double issZ = issR * Math.cos(issLat);

System.out.println("ISS\nx: " + issX);

System.out.println("y: " + issY);

System.out.println("z: " + issZ);

//Convert to cartesian

double posX = posR * Math.sin(posLat) * Math.cos(posLong);

double posY = posR * Math.sin(posLat) * Math.sin(posLong);

double posZ = posR * Math.cos(posLat);

System.out.println("\nPOS\nx: " + posX);

System.out.println("y: " + posY);

System.out.println("z: " + posZ);

//Calculate angle (I'm not sure which angle is which :D)

double angleYZ = Math.atan2(issY - posY, issZ - posZ)*180/Math.PI;

double angleYX = Math.atan2(issY - posY, issX - posX)*180/Math.PI;

//Another try to calculate the angle...

double angle = Math.toDegrees(Math.atan2(Math.sqrt(Math.pow(issX - posX, 2) + Math.pow(issY - posY, 2)), issZ - posZ))+90d;

double angle2 = Math.toDegrees(Math.atan2(Math.sqrt(Math.pow(issX - posX, 2) + Math.pow(issY - posY, 2)), issX - posX))+90d;

System.out.println();

System.out.println("Angle X: " + angleYZ);

System.out.println("Angle Z: " + angleYX);

System.out.println(angle);

System.out.println(angle2);

}

}

class Math {

final static double PI = java.lang.Math.PI;

public static double cos(double x) {

return java.lang.Math.cos(x * Math.PI/180.0);

}

public static double sin(double x) {

return java.lang.Math.sin(x * Math.PI/180.0);

}

public static double atan2(double x, double y) {

return java.lang.Math.atan2(x, y);

}

public static double toDegrees(double angrad) {

return java.lang.Math.toDegrees(angrad);

}

public static double pow(double a, double b) {

return java.lang.Math.pow(a, b);

}

public static double sqrt(double a) {

return java.lang.Math.sqrt(a);

}

}

2016-09-23

LsHallo

+1

假设你改变你的ATAN2使用相同的角度单位为你的正弦和余弦函数,我觉得倾斜角度'ATAN2( issR * cos(issLat - posLat) - posR,issR * sin(issLat - posLat))'(0为北向水平,90度向上,180度es为南向,-90度为向下),平移角为atan2(issR * sin(issLong - posLong),issR * cos(issLong - posLong) - posR)'(0为北,90度为东, 180度为南,-90度为西)。但我可能是错的。 –

+1

你是我的英雄!它非常好,非常感谢你! –

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值