假设我有一个两轮物体,每个轮子都有一个独立的速度(分别为左右轮的lWheelV和rWheelV)。每个车轮的速度限制在[-1,1]范围内(即介于-1和1之间)。
在下图中可能更容易想象:
我需要用什么数学来描述这样一个对象,更重要的是我如何实现可以在Java中复制此行为的软件。
答案 0 :(得分:1)
这取决于车辆宽度,fps等等一大堆......
然而,一些提示:
要在一帧中计算车辆的旋转,您可以使用arctan功能。
float leftWheel = 1.0f;
float rightWheel = 0.5f;
float vehicleWidth = 1.0f;
float diff = rightWheel - leftWheel;
float rotation = (float) Math.atan2(diff, vehicleWidth);
要确定车辆沿其轴移动的速度,请使用:
float speedAlongAxis = leftWheel + rightWheel;
speedAlongAxis *= 0.5f;
按照第一个提示中计算的角度旋转车辆的轴:
float axisX = ...;
float axisY = ...;
/* Make sure that the length of the vector (axisX, axisY) is 1 (which is
* called 'normalised')
*/
float x = axisX;
float y = axisY;
axisX = (float) (x * Math.cos(rotation) - y * Math.sin(rotation));
axisY = (float) (x * Math.sin(rotation) + y * Math.cos(rotation));
将车辆移过轴:
float vehicleX = ...;
float vehicleY = ...;
vehicleX += axisX * speedAlongAxis;
vehicleY += axisY * speedAlongAxis;
normalise()
方法如下所示:
public float normalise()
{
float len = (float) Math.sqrt(x * x + y * y);
x /= len;
y /= len;
return len;
}