User Name
Password

Go Back   Planetarion Forums > Non Planetarion Discussions > Programming and Discussion
Register FAQ Members List Calendar Arcade Today's Posts

Reply
Thread Tools Display Modes
Unread 9 Jul 2013, 00:20   #1
Spinner
Founder of Planetarion
 
Join Date: Mar 2000
Location: Oslo, Norway
Posts: 543
Spinner has a brilliant futureSpinner has a brilliant futureSpinner has a brilliant futureSpinner has a brilliant futureSpinner has a brilliant futureSpinner has a brilliant futureSpinner has a brilliant futureSpinner has a brilliant futureSpinner has a brilliant futureSpinner has a brilliant futureSpinner has a brilliant future
Math, angles, atan2 etc?

Is anyone in here fairly proficient in these aspects? Apparently, I'm a noob, and can't quite get things to work.
It's a bit embarrassing, but here we go:
First of all, think 2D.

I have a missile being launched, headed for a specific target.
The missile has typical attributes like x, y, acceleration, speed, turning-speed etc.
More importantly, it has a Direction (- PI to PI) and a similar DirectionToTarget (-PI to PI).
These directions are in radians, as you know by now, after using the atan2-formula on DX,DY.

Now, in my limited understanding, I thought I could simply DECREASE the Direction if Direction was GREATER than DirectionToTarget, and if it SMALLER, I would simply INCREASE it. And in some cases, this will work. However, in some cases, my missile will rather turn 265 degrees left, in stead of 95 degrees to the right...
So I thought, ok, we need to cater for the 4 different "quadrants" that are possible here, but I have not been able to get this stuff right.....

Can anyone tell me how I can alter my missiles direction "in the right direction" towards the "direction to the target" and have it pick the shorter way around every time?

Any takers?
__________________
- Spinner
Original creator of Planetarion, ManagerLeague and AD2460.
Spinner is offline   Reply With Quote
Unread 9 Jul 2013, 06:10   #2
Influence
Finally retired
 
Join Date: Mar 2007
Posts: 788
Influence is a splendid one to beholdInfluence is a splendid one to beholdInfluence is a splendid one to beholdInfluence is a splendid one to beholdInfluence is a splendid one to beholdInfluence is a splendid one to beholdInfluence is a splendid one to beholdInfluence is a splendid one to behold
Re: Math, angles, atan2 etc?

well, mathematically i am more of a noob than urself probably, but what i would do is check if the angle is greater than 180 degrees, and turn (360 - angle) degrees to the other side if it is. however, i don't know enough of the material to say that's really a solution.
__________________
don't be an arse, join [TiT]

In the absence of the good old TiT alliance, look me up in VGN
Influence is offline   Reply With Quote
Unread 9 Jul 2013, 13:45   #3
Spinner
Founder of Planetarion
 
Join Date: Mar 2000
Location: Oslo, Norway
Posts: 543
Spinner has a brilliant futureSpinner has a brilliant futureSpinner has a brilliant futureSpinner has a brilliant futureSpinner has a brilliant futureSpinner has a brilliant futureSpinner has a brilliant futureSpinner has a brilliant futureSpinner has a brilliant futureSpinner has a brilliant futureSpinner has a brilliant future
Re: Math, angles, atan2 etc?

I don't know if that would have worked as I intended, but maybe

I solved it going a completely different way.

From the missile, I project 3 lines, one one a slightly lower angle, one on a slightly higher, and one on the current direction of the missile. Then I check the distance from each of the endpoints to the targets location, and pick the option that provides the shortest distance!

The good thing about this, is that it provides a cool-looking heat-seeker-effect, while the downside might be 3 cos-operations, 3 sin-operations and 3 square-root operations. These days though, I think we have Mhz enough to spend on it

Thanks for your time though, and your suggestion!
__________________
- Spinner
Original creator of Planetarion, ManagerLeague and AD2460.
Spinner is offline   Reply With Quote
Reply



Forum Jump


All times are GMT +1. The time now is 02:57.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2002 - 2018