已知地球上的2点坐标,A和B,求A,B线上 任意点位置。
根据已知的A点和B点,计算X点坐标,X在A,B 线上,AX距离已知。
public static GeoPoint caculateWGS84GeoPoint(GeoPoint aPoint, GeoPoint bPoint, double distance_ax_in_meter) {if (geoCalc == null) {geoCalc = new GeodeticCalculator(); }double startBearing = AngleUtil.getAngel(aPoint, bPoint); GlobalCoordinates start = new GlobalPosition(aPoint.getLatitude(), aPoint.getLongitude(), aPoint.getAltitude()); GlobalCoordinates x = geoCalc.calculateEndingGlobalCoordinates(Ellipsoid.WGS84, start, startBearing, distance_ax_in_meter); GeoPoint xPoint = new GeoPoint(x.getLongitude(), x.getLatitude()); return xPoint; }
/** * https://blog.csdn.net/u010980446/article/details/45268299 */ public class AngleUtil {public static void main(String[] args) {MyLatLng A=new MyLatLng(113.249648,23.401553); MyLatLng B=new MyLatLng(113.246033,23.403362); System.out.println(getAngle(A,B)); }/** * 已知道A 点,B点的经纬度,84坐标系, X点在A和B之间.[Ax<AB AB取穿过地球球心最短弧长这条] 求X坐标位置 * @param A * @param B * @param distance_in_km_ax * @return */ public static MyLatLng caculateRawGeoPoint(MyLatLng A, MyLatLng B, double distance_in_km_ax){MyLatLng newMyLatLng=null; double angle = getAngle(A,B); //这个有问题. double distance_A_X_in_KM = GeoPointTransform.distance(new GeoPoint(A.m_Longitude,A.m_Latitude),new GeoPoint(B.m_Longitude,B.m_Latitude))/1000.0d; if(distance_A_X_in_KM<=distance_in_km_ax) {newMyLatLng = getMyLatLng(A, distance_in_km_ax, angle); }else{newMyLatLng = getMyLatLng(A, Math.max(distance_in_km_ax,distance_A_X_in_KM), angle); System.out.println("请注意:X点不在A点和B点之间,您是不是要计算AB线上,在B之后的点"+newMyLatLng); newMyLatLng = null; }return newMyLatLng; }/** * 求B点经纬度 * @param A 已知点的经纬度, * @param distanceInKM AB两地的距离 单位km * @param angle AB连线与正北方向的夹角(0~360) * @return B点的经纬度 */ public static MyLatLng getMyLatLng(MyLatLng A,double distanceInKM,double angle){double dx = distanceInKM*1000*Math.sin(Math.toRadians(angle)); double dy= distanceInKM*1000*Math.cos(Math.toRadians(angle)); double bjd=(dx/A.Ed+A.m_RadLo)*180./Math.PI; double bwd=(dy/A.Ec+A.m_RadLa)*180./Math.PI; return new MyLatLng(bjd, bwd); }/** * 求B点经纬度 * @param wgs84GeoPointA 已知点的经纬度, * @param distanceInMeter AB两地的距离 单位km * @param angle AB连线与正北方向的夹角(0~360) * @return B点的经纬度 */ public static GeoPoint caculateRawGeoPoint(GeoPoint wgs84GeoPointA,double distanceInMeter,double angle){double dx = distanceInMeter*Math.sin(Math.toRadians(angle)); double dy= distanceInMeter*Math.cos(Math.toRadians(angle)); MyLatLng A = new MyLatLng(wgs84GeoPointA.getLongitude(),wgs84GeoPointA.getLatitude()); double bjd=(dx/A.Ed+A.m_RadLo)*180./Math.PI; double bwd=(dy/A.Ec+A.m_RadLa)*180./Math.PI; GeoPoint newGeoPoint = new GeoPoint(bjd,bwd,0.0); return newGeoPoint; }/** * 获取AB连线与正北方向的角度 * @param A A点的经纬度 * @param B B点的经纬度 * @return AB连线与正北方向的角度(0~360) */ public static double getAngle(MyLatLng A,MyLatLng B){double dx=(B.m_RadLo-A.m_RadLo)*A.Ed; double dy=(B.m_RadLa-A.m_RadLa)*A.Ec; double angle=0.0; angle=Math.atan(Math.abs(dx/dy))*180./Math.PI; double dLo=B.m_Longitude-A.m_Longitude; double dLa=B.m_Latitude-A.m_Latitude; if(dLo>0&&dLa<=0){angle=(90.-angle)+90; }else if(dLo<=0&&dLa<0){angle=angle+180.; }else if(dLo<0&&dLa>=0){angle= (90.-angle)+270; }return angle; }public static double getAngel(GeoPoint wgs84GeoPointA, GeoPoint wgs84GeoPointB){MyLatLng A = new MyLatLng(wgs84GeoPointA.getLongitude(),wgs84GeoPointA.getLatitude()); MyLatLng B = new MyLatLng(wgs84GeoPointB.getLongitude(),wgs84GeoPointB.getLatitude()); double angel=0.0; angel=getAngle(A,B); return angel; }static class MyLatLng {final static double Rc=6378137; final static double Rj=6356752;//6356725 double m_LoDeg,m_LoMin,m_LoSec; double m_LaDeg,m_LaMin,m_LaSec; double m_Longitude,m_Latitude; double m_RadLo,m_RadLa; double Ec; double Ed; public MyLatLng(double longitude,double latitude){m_LoDeg=(int)longitude; m_LoMin=(int)((longitude-m_LoDeg)*60); m_LoSec=(longitude-m_LoDeg-m_LoMin/60.)*3600; m_LaDeg=(int)latitude; m_LaMin=(int)((latitude-m_LaDeg)*60); m_LaSec=(latitude-m_LaDeg-m_LaMin/60.)*3600; m_Longitude=longitude; m_Latitude=latitude; m_RadLo=longitude*Math.PI/180.; m_RadLa=latitude*Math.PI/180.; Ec=Rj+(Rc-Rj)*(90.-m_Latitude)/90.; Ed=Ec*Math.cos(m_RadLa); }}/** * 已知WGS84坐标系 A 点,B点, X 在AB 弧线上, 且是最短的这条, AX距离已知,求X点坐标. * @param aPoint * @param bPoint * @param distance_ax_in_meter * @return */ public static GeoPoint caculateRawGeoPoint(GeoPoint aPoint, GeoPoint bPoint, double distance_ax_in_meter){MyLatLng a= new MyLatLng(aPoint.getLongitude(),aPoint.getLatitude()); MyLatLng b = new MyLatLng(bPoint.getLongitude(),bPoint.getLatitude()); double angle=getAngle(a,b); //getAngle(a,x)==getAngle(a,b) MyLatLng x= getMyLatLng(a,distance_ax_in_meter/1000.0,angle); GeoPoint xPoint = new GeoPoint(x.m_Longitude,x.m_Latitude); return xPoint; }/** * https://stackoverflow.com/questions/837872/calculate-distance-in-meters-when-you-know-longitude-and-latitude-in-java * @return 这个精准度比较差 */ public static double rawDistance(GeoPoint wgs84GeoPointA, GeoPoint wgs84GeoPointB) {double earthRadius = 6371000; //meters double dLat = Math.toRadians(wgs84GeoPointB.getLatitude()-wgs84GeoPointA.getLatitude()); double dLng = Math.toRadians(wgs84GeoPointB.getLongitude()-wgs84GeoPointA.getLongitude()); double a = Math.sin(dLat/2) * Math.sin(dLat/2) +Math.cos(Math.toRadians(wgs84GeoPointA.getLatitude())) * Math.cos(Math.toRadians(wgs84GeoPointB.getLatitude())) *Math.sin(dLng/2) * Math.sin(dLng/2); double c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a)); double distanceAB = earthRadius * c; return distanceAB; } }
/* * Geodesy by Mike Gavaghan * * http://www.gavaghan.org/blog/free-source-code/geodesy-library-vincentys-formula/ * * Copyright 2007 Mike Gavaghan - mike@gavaghan.org * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /* * BitCoin tips graciously accepted at 1FB63FYQMy7hpC2ANVhZ5mSgAZEtY1aVLf */ package org.gavaghan.geodesy; /** * <p> * Encapsulates a three dimensional location on a globe (GlobalCoordinates * combined with an elevation in meters above a reference ellipsoid). * </p> * <p> * See documentation for GlobalCoordinates for details on how latitude and * longitude measurements are canonicalized. * </p> * * @author <a href="mailto:mike@gavaghan.org">Mike Gavaghan</a> */ public class GlobalPosition extends GlobalCoordinates {/** Elevation, in meters, above the surface of the ellipsoid. */ private double mElevation; /** * Creates a new instance of GlobalPosition. * * @param latitude * latitude in degrees * @param longitude * longitude in degrees * @param elevation * elevation, in meters, above the reference ellipsoid */ public GlobalPosition(double latitude, double longitude, double elevation){super(latitude, longitude); mElevation = elevation; }/** * Creates a new instance of GlobalPosition. * * @param coords * coordinates of the position * @param elevation * elevation, in meters, above the reference ellipsoid */ public GlobalPosition(GlobalCoordinates coords, double elevation){this(coords.getLatitude(), coords.getLongitude(), elevation); }/** * Get elevation. * * @return elevation about the ellipsoid in meters. */ public double getElevation(){return mElevation; }/** * Set the elevation. * * @param elevation * elevation about the ellipsoid in meters. */ public void setElevation(double elevation){mElevation = elevation; }/** * Compare this position to another. Western longitudes are less than * eastern longitudes. If longitudes are equal, then southern latitudes are * less than northern latitudes. If coordinates are equal, lower elevations * are less than higher elevations * * @param other * instance to compare to * @return -1, 0, or +1 as per Comparable contract */ public int compareTo(GlobalPosition other){int retval = super.compareTo(other); if (retval == 0){if (mElevation < other.mElevation) retval = -1; else if (mElevation > other.mElevation) retval = +1; }return retval; }/** * Get a hash code for this position. * * @return hash code */ @Override public int hashCode(){int hash = super.hashCode(); if (mElevation != 0) hash *= (int) mElevation; return hash; }/** * Compare this position to another object for equality. * * @param obj object to compare to * @return 'true' if objects are equal */ @Override public boolean equals(Object obj){if (!(obj instanceof GlobalPosition)) return false; GlobalPosition other = (GlobalPosition) obj; return (mElevation == other.mElevation) && (super.equals(other)); }/** * Get position as a string. */ @Override public String toString(){StringBuffer buffer = new StringBuffer(); buffer.append(super.toString()); buffer.append("elevation="); buffer.append(Double.toString(mElevation)); buffer.append("m"); return buffer.toString(); } }
已知地球上的2点坐标,A和B,求A,B线上 任意点位置。相关推荐
- java 球面距离_[置顶] C语言实验题:已知地球上两点的经度和纬度求其球面距离...
要求:地球的平均半径为6371千米,已知地球上两个城市A.B的经度和纬度,编程序求出这两个城市之间的地面距离. 首先,固定两点,a(x1,y1,z1),b(x2,y2,z2). 由空间解析几何及向量知 ...
- 已知基点的经纬度,根据方位角和运动距离求另外一点的经纬度
1. 已知基点的经纬度,根据方位角和运动距离求另外一点的经纬度 1.1 需求概述及图解 假设方位角是α, 那从点1到点2的平移距离分别如下所示dsinα, dcosα. 这里正北为0度.已知基点(点1 ...
- C语言编程b a化简,C语言编程,已知三角形的三边长a,b,c,计算求三角... 如果三角形三边长 a,b,c,满足( )那么这个三角形......
导航:网站首页 > C语言编程,已知三角形的三边长a,b,c,计算求三角... 如果三角形三边长 a,b,c,满足( )那么这个三角形... C语言编程,已知三角形的三边长a,b,c,计算求三角 ...
- 已知点 A(x1, y1) 和点 B(x2, y2), 求线段AB的垂直平分线.
已知点 A(x1, y1) 和点 B(x2, y2), 求线段AB的垂直平分线. (求线段的垂直平分线)(求线段的中垂线) 1. 求得直线AB的斜率k, 则可以求得中垂线的斜率为 -1 / k. (垂 ...
- 每日一题(42)—— 已知一个数组table,用一个宏定义,求出数据的元素个数
已知一个数组table,用一个宏定义,求出数据的元素个数. // 总大小除以第一个元素的大小 #define TNTBL (sizeof(table)/sizeof(table[0]))
- 已知抛物线与直线相交两点和抛物线顶点,求抛物线和直线所围成的面积?
已知抛物线与直线相交两点和抛物线顶点,求抛物线和直线所围成的面积? 顶点:p1(-b/2a),((4ac-b^2)/2a): 抛物线方程:y=ax^2+bx+c; 直线方程:y=k*x+b; 已知:p ...
- 已知一个二维数组A 表示一个矩阵,求AT。 其中,AT 表示矩阵的转置。矩阵转置的含义:表示把一个矩阵行列互换。
已知一个二维数组A 表示一个矩阵,求AT. 其中,AT 表示矩阵的转置.矩阵转置的含义:表示把一个矩阵行列互换. //传入需要验证的数组,在main里面调用该方法public static void ...
- python计算1的平方减2的平方加3的平方减4的平方怎么算_已知X的平方加4x减一等于零 求2x的四次方加八X的三次方减四X的平方减八X加一的值...
已知X的平方加4x减一等于零 求2x的四次方加八X的三次方减四X的平方减八X加一的值以下文字资料是由(历史新知网www.lishixinzhi.com)小编为大家搜集整理后发布的内容,让我们赶快一起来 ...
- 有 20 枚硬币,可能包括 4 种类型:1 元、5 角、1 角和 5 分。已知 20 枚硬币的总价值为 10 元,求各种硬币的数量。
有以下问题 有 20 枚硬币,可能包括 4 种类型:1 元.5 角.1 角和 5 分.已知 20 枚硬币的总价值为 10 元,求各种硬币的数量. 首先我们先来分析一下,每种硬币的情况,1 元最多 10 ...
最新文章
- showModalDialog和showModelessDialog使用心得
- 2015/09/09夜晚js继续学习
- [转载]我的博后申请经历从陶瓷到Offer过程
- Zabbix 钉钉报警
- mysql ( )连接_MySQL中concat函数(连接字符串)
- Vue与服务端数据交互 [ axios ]
- 深拷贝浅拷贝的一些理解
- Python正则表达式案例一则:单词非两端字符改为小写
- Cisco STP生成树协议
- 网络安装ubuntu操作系统
- iapp退出软件按钮代码_还在为金蝶财务软件发愁吗?超详细!金蝶财务软件实操流程,速收...
- html彻底隐藏源代码禁止抓包,如何彻底禁止查看网页源代码
- VC++实现快速截屏
- java获取大写字母_获取中文大写首字母java实现
- 计算机丢失OX0000007B,win10系统应用程序无法正常启动0x000007b的解决办法
- 全国失信被执行人黑名单信息查询API接口
- java 实现手机号码(String)校验----两种方法
- 小程序接入h5页面_微信小程序跳转外部链接(h5页面)以及数据交互
- Win32显示隐藏任务栏
- Scaner的一个异常