【问题标题】:Calculate trajectory given a coordinate and angle计算给定坐标和角度的轨迹
【发布时间】:2015-02-27 19:27:25
【问题描述】:

鉴于以下情况:
- 起点(坐标)
- 角度(度)
- 速度

.. 我想计算给定的轨迹。
例如下图 w/ 速度 1:(10,10) (9,9) (8,8) (7,7) ..

它应该能够向各个方向移动。
如何计算?

【问题讨论】:

  • 在我生活的 2D 和 3D 世界中,速度矢量只有 2 或 3 个分量。您发布的“速度”是多少?如果你的姿势正确,这是一个高中三角问题。
  • 这是一个 2D 世界速度基本上就是它行进的速度
  • 是的,我明白了。 (不需要“基本上”。)我是说速度向量中应该有两个数字,仅此而已。

标签: math geometry angle


【解决方案1】:

如果你有角度和速度(标量),x 和 y 方向的分量很简单:

vx = (speed)*cos(angle)

vy = (speed)*sin(angle)

对于大多数语言来说,角度必须是弧度,而不是度数。确保你转换它。

所以如果你在时间 t1 有一个点 (ux, uy),那么在时间 t2 的位置是:

ux(t2) = ux(t1) + vx*(t2-t1)

uy(t2) = uy(t1) + vy*(t2-t1)

让我们看看它在 Java 中的样子:

/**
 * Method for updating a position giving speed, angle, and time step
 * @param original coordinates in x, y plane
 * @param speed magnitude; units have to be consistent with coordinates and time
 * @param angle in radians
 * @param dtime increment in time 
 * @return new coordinate in x, y plane
 */
public Point2D.Double updatePosition(Point2D.Double original, double speed, double angle, double dtime) {
    Point2D.Double updated = new Point2D.Double();    
    updated.x = original.x + speed*Math.cos(angle)*dtime;
    updated.y = original.y + speed*Math.sin(angle)*dtime;    
    return updated;
}

【讨论】:

猜你喜欢
  • 2012-09-08
  • 1970-01-01
  • 2014-04-11
  • 2022-08-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-08-04
相关资源
最近更新 更多