Generate random GPS Points on a Radius

270 Views Asked by At

Is there a way to generate random Points between 2 points on a given Radius? As you can see in my drawing: Point A and Point B is known. Also r is known. Im looking for a way to generate points 1,2,3 between G and F. I don't have points G and F. Its not a must to have those G and F points. I took those points to define a range somehow. For example a given distance between points 1,2,3 could be such a definition.. so to say random points on a radius with a 5 km distance between each other with a known bearing. Is there a package or a way to achieve this? Thank you very much in advance!

Points on a radius

1

There are 1 best solutions below

0
On BEST ANSWER

After a bit of research i use this solution. I hope some one else will find it interresting.

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)
  
}