在半径上生成随机的GPS点

问题描述

有没有一种方法可以在给定半径的2个点之间生成随机点? 正如您在我的图形中看到的:A点和B点是已知的。 r也是已知的。我正在寻找一种在G和F之间生成点1,2,3的方法。我没有G和F点。拥有这些G和F点不是必须的。我以这些观点以某种方式定义了范围。例如,点1、2、3之间的给定距离可以是这样的定义。也就是说,在半径为5 km的半径上的任意点之间具有已知方位。是否有解决方案或方法? 提前非常感谢您!

Points on a radius

解决方法

经过一些研究,我使用了该解决方案。 我希望其他人会发现这很有趣。

points_on_a_circle <- function(p1,p2,rb_wgs84,km_distance){
  
  LatDec = p1[2]
  LonDec = p1[1]
  b <- geosphere::bearingRhumb(p1,p2)
  Km = km_distance
  ER <- 6371 #Mean Earth radius in kilometers. Change this to 3959 and you will have your function working in miles.
  AngDeg <- seq((b - 40),(b + 40)) #angles in degrees / Set G and F borders
  Lat1Rad <- LatDec*(pi/180)#Latitude of the center of the circle in radians
  Lon1Rad <- LonDec*(pi/180)#Longitude of the center of the circle in radians
  AngRad <- AngDeg*(pi/180)#angles in radians
  Lat2Rad <- asin(sin(Lat1Rad)*cos(Km/ER) + cos(Lat1Rad)*sin(Km/ER)*cos(AngRad)) #Latitude of each point of the circle rearding to angle in radians
  Lon2Rad <- Lon1Rad + atan2(sin(AngRad)*sin(Km/ER)*cos(Lat1Rad),cos(Km/ER) - sin(Lat1Rad)*sin(Lat2Rad))#Longitude of each point of the circle rearding to angle in radians
  Lat2Deg <- Lat2Rad*(180/pi)#Latitude of each point of the circle rearding to angle in degrees (conversion of radians to degrees deg = rad*(180/pi) )
  Lon2Deg <- Lon2Rad*(180/pi)#Longitude of each point of the circle rearding to angle in degrees (conversion of radians to degrees deg = rad*(180/pi) )
  point_on_circle <- cbind(Lon2Deg,Lat2Deg)
  
  return(point_on_circle)
  
}

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...