dpikoto468637 2016-07-28 08:13
浏览 22

如何以设定的速度在2 gps点之间移动?

I'm trying to create a function that will let me give 2 arguments, a new location and a speed to travel at (in meters / second)

It looks like 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

    a := 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 to travel in a straight line, in Kilometers


}

The only thing I'm having trouble with is thinking of the formula to make the latitude, start at its current position, and end up at its new position over a set amount of time.

So say the person changed the latitude from 56.65 to 58.12 and I told it to travel at 1.3m/s how can I accomplish this. Thanks.

  • 写回答

1条回答 默认 最新

  • drnzpd579935 2016-07-28 09:27
    关注

    If I understand your question, your goal is to compute all the intermediate points between two location, starting from one location and going to the second one using a specified speed.

    If I'm correct, the following is how I would get a first solution. If anyone can improve this, I'd appreciate.

    On the proj4 documentation, you can find a lot of information on how to compute distance between two points.

    Starting from points A to reach B with a given speed (m/s), just means to compute each seconds a point A' that is at a distance m from A on the line AB.

    In a more algorithmic way (based on Vincenty's formula):

    func (l *Location) Move(newLoc *Location, speed float64) Location {
        azimuthA, azimuthB, d := inverseVincenty(l, newLoc)
    
        // Use the direct vincenty's formula.
        // Here transform speed to get the correct value
        // without transformation, since speed is in m/s,
        // the resulting point will be at speed(m) distance from l.
        res := directVincenty(l, speed, azimuthA)
    
        // Now res shall contain your new point.
        return res
    }
    
    func main() {
        // init A and B and speed values.
        C := A // to conserve A position.
        t := time.Tick(1* time.Second)
        for stop := false; !stop; {
            select {
                case <- t:
                C = C.Move(B, speed)
                case // here a break condition:
                    stop = true
            }
        }
    }
    

    I think thats a start, any comment is appreciate on this answer.

    评论

报告相同问题?

悬赏问题

  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 划分vlan后不通了
  • ¥15 GDI处理通道视频时总是带有白色锯齿
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大