go - How can I move between 2 gps points at a set speed? -
i'm trying create function let me give 2 arguments, new location , speed travel @ (in meters / second)
it looks this:
func (l *location) move(newloc *location, speed float64) { r := 6371.0 // kilometers lat1 := l.latitude * math.pi / 180 lat2 := l.longitude * math.pi / 180 difflat := (newloc.latitude - l.latitude) * math.pi / 180 difflon := (newloc.longitude - l.longitude) * math.pi / 180 := math.sin(difflat/2)*math.sin(difflat/2) + math.cos(lat1)*math.cos(lat2)*math.sin(difflon/2)*math.sin(difflon/2) c := 2 * math.atan2(math.sqrt(a), math.sqrt(1-a)) distancetomove := r * c // distance travel in straight line, in kilometers }
the thing i'm having trouble thinking of formula make latitude, start @ current position, , end @ new position on set amount of time.
so person changed latitude 56.65
58.12
, told travel @ 1.3m/s
how can accomplish this. thanks.
if understand question, goal compute intermediate points between 2 location, starting 1 location , going second 1 using specified speed.
if i'm correct, following how first solution. if can improve this, i'd appreciate.
on proj4 documentation, can find lot of information on how compute distance between 2 points.
starting points reach b given speed (m/s), means compute each seconds point a' @ distance m on line ab.
in more algorithmic way (based on vincenty's formula):
func (l *location) move(newloc *location, speed float64) location { azimutha, azimuthb, d := inversevincenty(l, newloc) // use direct vincenty's formula. // here transform speed correct value // without transformation, since speed in m/s, // resulting point @ speed(m) distance l. res := directvincenty(l, speed, azimutha) // res shall contain new point. return res } func main() { // init , b , speed values. c := // conserve position. t := time.tick(1* time.second) stop := false; !stop; { select { case <- t: c = c.move(b, speed) case // here break condition: stop = true } } }
i think thats start, comment appreciate on answer.
Comments
Post a Comment