For a few months now, I’ve been dabbling in the maths of some simple 2D motion. Around November, I derived an equation expressing x-position (x) as a function of time (t). It is of the form:
x = i + jt + k cos(lt + m)
where i, j, k, l and m are constants. For maths newbies like myself, I point out that the equation is of a cosine (the k cos(lt+m) bit) added to a line (i + jt), giving a wiggly line that is trending up or down. It looks like the red line in this plot:

Here is my problem. In order to determine if (and when) the object will hit a left or right wall, I need to find the values of t where x is 1 or -1 – shown in blue on the above picture.
I’ve spent quite some time on this, and I have some interesting equations that give limits to the solution(s) I am interested in, but nothing precise enough to work with.
Despite many hours spent on this, my high school maths is not enough, Google has been no help and the books in Dymocks don’t seem to be of any use either.
Can anybody out there show me how to solve the equation for t, or point me to some useful resource?
Comments
Most trig equations cannot be solved for an exact
value. Your best bet is to learn a little
differential calculus if you haven't already and
then use Newton's Method (google it) to quickly
get approximations as close as you may need.
Newtons method will probably not help you very much. It will give false solutions in the face of local minima (of which your function clearly has many).
Is your goal to find the solutions or is it to have a behaviour upon striking the wall? If you're trying to animate something, then you might as well forget the maths and just calculate each point as you go and compare it to -1 & 1.
Daniel:
The goal is to find if the object will hit the wall in the next few seconds. The function will be used by the AI to avoid the wall.
xplat:
We do know where the local maxima and minima are - maxima are at (lt + m) = 0, 2pi, 4pi, ... and minima are at (lt + m) = pi, 3pi, 5pi, ... - so Newton's method would work.
If I can't find the answer in a single equation, then that's what I'll do. Shouldn't be too calculation intensive - I'm only interested in the smallest positive solution for t.
Thanks both for your thoughts.
a
Actually, the derivative of your function is:
j - kl sin (lt + m)
So your local minima/maxima occur when
j = kl sin (lt + m)
(j / kl) = sin ( lt + m )
t = (asin [j / kl] - m) / l
Though if the value of j/kl is close to zero, you shuold be able to use your approximation from earlier to use newtons method to get to the intersections.
Daniel:
Duh. Of course you are right. In fact, if |j| (j is the slope of the underlying line) is larger than |kl| (kl is the maximum slope of the cos part), then there won't be any local maxima or minima.
a
I don't really think this will help you solve your specific problem, but O'Reilly sells a book called Physics for Game Developers which is pretty good and covers collisions. Might prove to be helpful.