chimpz
- 7
- 0
(this is all in context to a java 2d object and is not homework related)
I have an object with velocity v and position x.
Its acceleration is directly proportional to velocity squared ie a=k v^{2}.
Given the objects initial velocity u and its initial position x_{0} how would i work out its velocity and position at time t?
I have tried integrating:
a = \frac{dv}{dt} = kv^{2}
\int^{v}_{u} v^{-2} dv = \int^{t}_{0} k dt
\frac{1}{u} -\frac{1}{v} = kt
v = \frac{1}{\frac{1}{u} - kt}
tbh I got a lot further while writing this post than I did trying to work it out before
trying to get the new position:
\int v^{-2} dv = \int k dt
-\frac{1}{v} = kt
v = \frac{dx}{dt} = -\frac{1}{kt}
\int^{x}_{x_{0}}1\:dx=\int^{t}_{0}-\frac{1}{kt}dt
x-x_{0}=-\frac{1}{k}\left[\:ln|t|\:\right]^{t}_{0}
But you can't ln|0| :/
So, without bounds:
x=-\frac{1}{k}ln|t| + c
Now I'm stuck.
How would I update the location?
Also, how would I implement drag while the engines were on?
Part of my code:
Pleased with myself for using the itex tags for the first time :D
Edit: could this be considered a hw-type question?
I have an object with velocity v and position x.
Its acceleration is directly proportional to velocity squared ie a=k v^{2}.
Given the objects initial velocity u and its initial position x_{0} how would i work out its velocity and position at time t?
I have tried integrating:
a = \frac{dv}{dt} = kv^{2}
\int^{v}_{u} v^{-2} dv = \int^{t}_{0} k dt
\frac{1}{u} -\frac{1}{v} = kt
v = \frac{1}{\frac{1}{u} - kt}
tbh I got a lot further while writing this post than I did trying to work it out before
trying to get the new position:
\int v^{-2} dv = \int k dt
-\frac{1}{v} = kt
v = \frac{dx}{dt} = -\frac{1}{kt}
\int^{x}_{x_{0}}1\:dx=\int^{t}_{0}-\frac{1}{kt}dt
x-x_{0}=-\frac{1}{k}\left[\:ln|t|\:\right]^{t}_{0}
But you can't ln|0| :/
So, without bounds:
x=-\frac{1}{k}ln|t| + c
Now I'm stuck.
How would I update the location?
Also, how would I implement drag while the engines were on?
Part of my code:
Code:
public void update(double delta) {
if (engines) {
double dv = Math.sqrt(2 * powerToWeight * delta);
Vector2f temp = dir.copy(); //dir is the direction of the engine's force
temp.scale(dv);
velo.add(temp);
double dx = dv * delta * 2 / 3;
temp = velo.copy();
temp.scale(dx);
loc.add(temp);
// TODO add drag
} else {
velo.i = (float) (1 / ( (1 / velo.i) - drag * delta ));
velo.j = (float) (1 / ( (1 / velo.j) - drag * delta ));
// TODO update location
}
}
Pleased with myself for using the itex tags for the first time :D
Edit: could this be considered a hw-type question?
Last edited: