矢量增量和在未知区域中移动

发布于 2024-08-31 23:11:36 字数 368 浏览 1 评论 0原文

我需要一些数学帮助,但我似乎找不到答案,任何文档链接将不胜感激。

这是我的情况,我不知道我在这个迷宫中的哪里,但我需要四处走动并找到回到起点的路。我正在考虑实现一个路径点列表,其中包含从 0,0 开始偏移的位置。这是一个二维笛卡尔平面。

我被赋予了 2 个属性,我的平移速度从 0-1 以及我的旋转速度从 -1 到 1。-1 是非常左的,+1 是非常右的。这些是速度而不是角度,所以这就是我的问题所在。如果我的平移速度为 0,并且为 0.2,我将不断地以低速向右转向。

如何计算给定这两个变量的偏移量?每次我迈出“一步”时我都可以存储它。

我只需要计算出给定平移和旋转速度的 x 和 y 项的偏移量。以及到达这些点的旋转。

任何帮助表示赞赏。

I was in need of a little math help that I can't seem to find the answer to, any links to documentation would be greatly appreciated.

Heres my situation, I have no idea where I am in this maze, but I need to move around and find my way back to the start. I was thinking of implementing a waypoint list of places i've been offset from my start at 0,0. This is a 2D cartesian plane.

I've been given 2 properties, my translation speed from 0-1 and my rotation speed from -1 to 1. -1 is very left and +1 is very right. These are speed and not angles so thats where my problem lies. If I'm given 0 as a translation speed and 0.2 I will continually turn to my right at a slow speed.

How do I figure out the offsets given these 2 variables? I can store it every time I take a 'step'.

I just need to figure out the offsets in x and y terms given the translations and rotation speeds. And the rotation to get to those points.

Any help is appreciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

回忆凄美了谁 2024-09-07 23:11:36

您的问题在几点上不清楚,所以我必须做出一些假设:

  1. 在每个时间间隔内,平移速度和旋转速度是恒定的。
  2. 您知道每个时间间隔内这些变量的值(并且您知道可用单位的旋转速度,例如每秒弧度,而不仅仅是“非常左”)。
  3. 你知道最初的航向。
  4. 您可以保持足够的精度,舍入误差不再是问题。

鉴于此,存在精确解。首先是简单的部分:

delta_angle = omega * delta_t

其中 omega 是角速度。行进的距离(可能沿着曲线)是

dist = speed * delta_t

,曲线的半径是

radius = dist / delta_angle

(当角速度接近零时,这会变得很大——我们稍后会处理这个问题。)如果角度(在开始时)区间)为零,定义为指向+x方向,那么区间内的平移很容易,我们将其称为 deta_x_0 和 delta_y_0:

delta_x_0 = radius * sin(delta_angle)
delta_y_0 = radius * (1 - cos(delta_angle))

因为我们希望能够处理非常小的 delta_angle并且半径非常大,我们将展开 sin 和 cos,并且仅当角速度接近零时才使用它:

dx0 = r * sin(da)     = (dist/da) * [ da - da^3/3! + da^5/5! - ...]
                     =  dist     * [  1 - da^2/3! + da^4/5! - ...]

dy0 = r * (1-cos(da)) = (dist/da) * [ da^2/2! - da^4/4! + da^6/6! - ...]
                     =  dist     * [   da/2! - da^3/4! + da^5/6! - ...]

但角度通常不等于零,因此我们必须旋转这些位移

dx = cos(angle) * dx0 - sin(angle) * dy0
dy = sin(angle) * dx0 - cos(angle) * dy0

Your question is unclear on a couple of points, so I have to make some assumptions:

  1. During each time interval, translation speed and rotational velocity are constant.
  2. You know the values of these variables in every time interval (and you know rotational velocity in usable units, like radians per second, not just "very left").
  3. You know initial heading.
  4. You can maintain enough precision that roundoff error is not a problem.

Given that, there is an exact solution. First the easy part:

delta_angle = omega * delta_t

Where omega is the angular velocity. The distance traveled (maybe along a curve) is

dist = speed * delta_t

and the radius of the curve is

radius = dist / delta_angle

(This gets huge when angular velocity is near zero-- we'll deal with that in a moment.) If angle (at the beginning of the interval) is zero, defined as pointing in the +x direction, then the translation in the interval is easy, and we'll call it deta_x_0 and delta_y_0:

delta_x_0 = radius * sin(delta_angle)
delta_y_0 = radius * (1 - cos(delta_angle))

Since we want to be able to deal with very small delta_angle and very large radius, we'll expand sin and cos, and use this only when angular velocity is close to zero:

dx0 = r * sin(da)     = (dist/da) * [ da - da^3/3! + da^5/5! - ...]
                     =  dist     * [  1 - da^2/3! + da^4/5! - ...]

dy0 = r * (1-cos(da)) = (dist/da) * [ da^2/2! - da^4/4! + da^6/6! - ...]
                     =  dist     * [   da/2! - da^3/4! + da^5/6! - ...]

But angle generally isn't equal to zero, so we have to rotate these displacements:

dx = cos(angle) * dx0 - sin(angle) * dy0
dy = sin(angle) * dx0 - cos(angle) * dy0
谜兔 2024-09-07 23:11:36

您可以分两个阶段进行。首先计算出方向的变化以获得新的方向向量,然后使用这个新方向计算出新的位置。类似于

angle = angle + omega * delta_t;

const double d_x = cos( angle );
const double d_y = sin( angle );

x = x + d_x * delta_t * v;
y = y + d_y * delta_t * v;

您在每一步中存储当前角度的位置。 (d_x, d_y) 是当前方向向量,omega 是您拥有的旋转速度。 delta_t 显然是你的时间步长,v 是你的速度。

将其分为两个不同的阶段可能太天真了。我不确定我是否真的考虑过太多,也没有测试过它,但如果它有效,请告诉我!

You could do it in two stages. First work out the change of direction to get a new direction vector and then secondly work out the new position using this new direction. Something like

angle = angle + omega * delta_t;

const double d_x = cos( angle );
const double d_y = sin( angle );

x = x + d_x * delta_t * v;
y = y + d_y * delta_t * v;

where you store your current angle out at each step. ( d_x, d_y ) is the current direction vector and omega is the rotation speed that you have. delta_t is obviously your timestep and v is your speed.

This may be too naive to split it up into two distinct stages. I'm not sure I haven't really thought it through too much and haven't tested it but if it works let me know!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文