根据Latitude/Longitude 计算方位,距离等

里面有详细的说明[url]http://www.movable-type.co.uk/scripts/latlong.html[/url]
比如计算距离
方法一,
double dist = 0.0; 
double deltaLat = Math.toRadians(latVal2 - latVal1);
double deltaLon = Math.toRadians(lonVal2 - lonVal1);
latVal1 = Math.toRadians(latVal1);
latVal2 = Math.toRadians(latVal2);
lonVal1 = Math.toRadians(lonVal1);
lonVal2 = Math.toRadians(lonVal2);
double earthRadius = 6371;
double a = Math.sin(deltaLat/2) * Math.sin(deltaLat/2) +
Math.cos(latVal1) * Math.cos(latVal2) * Math.sin(deltaLon/2) * Math.sin
(deltaLon/2);
double c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a));
dist = earthRadius * c;

方法二,
public static double calculateHaversineMI(double lat1, double long1, double lat2,double long2) {
double dlong = (long2 - long1) * (Math.PI / 180.0f);
double dlat = (lat2 - lat1) * (Math.PI / 180.0f);
double a = Math.pow(Math.sin(dlat / 2.0), 2)
+ Math.cos(lat1 * (Math.PI / 180.0f))
* Math.cos(lat2 * (Math.PI / 180.0f))
* Math.pow(Math.sin(dlong / 2.0), 2);
double c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
double d = 6367* c;

return d;
}


还有计算方位
double dLong = picLongitude - mLongitude; 
double y = (Math.sin(dLong) * Math.cos(picLatitude));
double x = (Math.cos(mLatitude) * Math.sin(picLatitude) -
Math.sin(mLatitude)*Math.cos(picLatitude)*Math.cos(dLong));
double angleDegreesWrongRange = Math.abs(Math.toDegrees(Math.atan2(y,
x)));
float angleDegrees = (float) ((angleDegreesWrongRange+360) % 360);

	public static String getDirection(float baseAzimuth){
String bearingText = "";
if ( (360 >= baseAzimuth && baseAzimuth >= 337.5) || (0 <= baseAzimuth && baseAzimuth <= 22.5) ) bearingText = "N";
else if (baseAzimuth > 22.5 && baseAzimuth < 67.5) bearingText = "NE";
else if (baseAzimuth >= 67.5 && baseAzimuth <= 112.5) bearingText = "E";
else if (baseAzimuth > 112.5 && baseAzimuth < 157.5) bearingText = "SE";
else if (baseAzimuth >= 157.5 && baseAzimuth <= 202.5) bearingText = "S";
else if (baseAzimuth > 202.5 && baseAzimuth < 247.5) bearingText = "SW";
else if (baseAzimuth >= 247.5 && baseAzimuth <= 292.5) bearingText = "W";
else if (baseAzimuth > 292.5 && baseAzimuth < 337.5) bearingText = "NW";

return bearingText;
}


都可以在里面找到答案
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
卫星方位角和俯仰角是卫星通信中的两个重要参数,用于计算卫星与地面站之间的通信覆盖范围。下面是计算卫星方位角和俯仰角的java代码,供您参考: ```java import java.lang.Math; public class SatelliteCoverage { public static void main(String[] args) { double latitude = 40.0; // 地面站纬度 double longitude = 116.0; // 地面站经度 double altitude = 0.0; // 地面站海拔高度 double satellite_latitude = 35.0; // 卫星纬度 double satellite_longitude = 138.0; // 卫星经度 double satellite_altitude = 35786.0; // 卫星高度 // 将经纬度转换为弧度 double lat_r = Math.toRadians(latitude); double lon_r = Math.toRadians(longitude); double sat_lat_r = Math.toRadians(satellite_latitude); double sat_lon_r = Math.toRadians(satellite_longitude); // 计算地心到地面站的距离 double R_earth = 6371.0; double r_ground = altitude + R_earth; double x_ground = r_ground * Math.cos(lat_r) * Math.cos(lon_r); double y_ground = r_ground * Math.cos(lat_r) * Math.sin(lon_r); double z_ground = r_ground * Math.sin(lat_r); // 计算地心到卫星的距离 double r_satellite = satellite_altitude + R_earth; double x_satellite = r_satellite * Math.cos(sat_lat_r) * Math.cos(sat_lon_r); double y_satellite = r_satellite * Math.cos(sat_lat_r) * Math.sin(sat_lon_r); double z_satellite = r_satellite * Math.sin(sat_lat_r); // 计算卫星在地心坐标系中的位置向量 double x_sat_rel = x_satellite - x_ground; double y_sat_rel = y_satellite - y_ground; double z_sat_rel = z_satellite - z_ground; // 计算卫星在地心坐标系中的方位角和俯仰角 double azimuth = Math.atan2(y_sat_rel, x_sat_rel); double elevation = Math.atan2(z_sat_rel, Math.sqrt(x_sat_rel*x_sat_rel + y_sat_rel*y_sat_rel)); // 将弧度转换为角度,并输出结果 double azimuth_deg = Math.toDegrees(azimuth); double elevation_deg = Math.toDegrees(elevation); System.out.println("Azimuth: " + azimuth_deg + " degrees"); System.out.println("Elevation: " + elevation_deg + " degrees"); } } ``` 以上代码可以计算出给定地面站和卫星位置的方位角和俯仰角。如果您需要计算多个位置的覆盖范围,可以将上述代码封装成一个函数,并循环调用即可。同时,您还可以结合地图API来实现更直观的可视化效果。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值