- #1
Ziks
- 6
- 0
This is a problem that's appeared in a game I am writing, and is a bit beyond the mechanics I can sort-of remember from high school.
The context is I have an object in 2D space which has a position [itex]p[/itex] and a velocity [itex]u[/itex], and a goal position [itex]G[/itex] I want that object to be in as soon as possible. At each time step, I can add an acceleration [itex]a = xA[/itex], where [itex]A[/itex] is the maximum acceleration and [itex]-1 \leq x \leq 1[/itex]. When the object reaches the goal position, its velocity should be 0.
I need to define a function [itex]f[/itex] with produces an acceleration [itex]a = f(G, A, p, u)[/itex]. This function should yield a sequence of states [itex]s_0, s_1, s_2 \ldots s_n[/itex] with the smallest possible length [itex]n[/itex], where each state [itex]s_i[/itex] is of the form [itex]s_i = (\mbox{position}, \mbox{velocity})[/itex].
The sequence of states must meet the criteria:
[itex]s_0 = (p, u) \\
s_n = (G, 0) \\
s_{i+1} = (\mbox{position}(s_i) + \mbox{velocity}(s_i), \mbox{velocity}(s_i) + f(G, A, \mbox{position}(s_{i+1}), \mbox{velocity}(s_i)))[/itex]
Also, [itex]-A \leq f(G, A, p, u) \leq A[/itex]
It's pretty trivial in one dimension, but extrapolating it to two dimensions is difficult because of the constraint on maximum acceleration.
My one dimensional solution:
[itex]f(G, A, p, u) = \begin{cases}
\mbox{min}(u + A, v) & u < v \\
\mbox{max}(u - A, v) & u > v \\
u & \mbox{otherwise}\end{cases}[/itex], where [itex]v=\sqrt{2A(G - p)}[/itex]
My reasoning here is that it should find out the largest possible velocity the object can travel at while still being able to slow and stop at the target, and then depending on whether that velocity has been exceeded or not the object will either accelerate or decelerate by the acceleration limit.
I'm at a loss as to how to extrapolate this into two dimensions, any help is appreciated.
The context is I have an object in 2D space which has a position [itex]p[/itex] and a velocity [itex]u[/itex], and a goal position [itex]G[/itex] I want that object to be in as soon as possible. At each time step, I can add an acceleration [itex]a = xA[/itex], where [itex]A[/itex] is the maximum acceleration and [itex]-1 \leq x \leq 1[/itex]. When the object reaches the goal position, its velocity should be 0.
I need to define a function [itex]f[/itex] with produces an acceleration [itex]a = f(G, A, p, u)[/itex]. This function should yield a sequence of states [itex]s_0, s_1, s_2 \ldots s_n[/itex] with the smallest possible length [itex]n[/itex], where each state [itex]s_i[/itex] is of the form [itex]s_i = (\mbox{position}, \mbox{velocity})[/itex].
The sequence of states must meet the criteria:
[itex]s_0 = (p, u) \\
s_n = (G, 0) \\
s_{i+1} = (\mbox{position}(s_i) + \mbox{velocity}(s_i), \mbox{velocity}(s_i) + f(G, A, \mbox{position}(s_{i+1}), \mbox{velocity}(s_i)))[/itex]
Also, [itex]-A \leq f(G, A, p, u) \leq A[/itex]
It's pretty trivial in one dimension, but extrapolating it to two dimensions is difficult because of the constraint on maximum acceleration.
My one dimensional solution:
[itex]f(G, A, p, u) = \begin{cases}
\mbox{min}(u + A, v) & u < v \\
\mbox{max}(u - A, v) & u > v \\
u & \mbox{otherwise}\end{cases}[/itex], where [itex]v=\sqrt{2A(G - p)}[/itex]
My reasoning here is that it should find out the largest possible velocity the object can travel at while still being able to slow and stop at the target, and then depending on whether that velocity has been exceeded or not the object will either accelerate or decelerate by the acceleration limit.
I'm at a loss as to how to extrapolate this into two dimensions, any help is appreciated.