Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Gaming > Development Programming Algorithms > Re: Algorithm t...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 4 of 8 Topic 588 of 675
Post > Topic >>

Re: Algorithm to find the shortest rotation using degrees?

by "m0rdred" <idlerstyle@[EMAIL PROTECTED] > Oct 27, 2006 at 03:06 PM

> I think you haven't taken a close look at the atan function.  I don't
> believe it's returning what you think it is.  Something like the
following
> is more useful:
>
> double CalcTheta( const JVEC2 Point1, const JVEC2 Point2 )
> {
>     double Theta = atan2( (Point2.x - Point1.x), (Point2.y - Point1.y) 
);
>     if ( Theta < 0 )
>         return 2 * PI + Theta;
>     else
>         return Theta;
> }
>
> First atan2 simplies it a little in that it takes two points so you
don't
> have to do the devisor.  It also handles the case if deltaX is 0 (in
your
> case would be devide by zero error).

Thanks Jim- based on your recommendation I came up with the following:

inline int shortestDirec(double start, double target)
{
	if(start < target)
	{
		if( (target - start) < (360 - target + start) )
			return 1;//turn left
		else
			return -1;//turn right
	}
	if(start > target)
	{
		if( (start - target) < (360 - start + target) )
			return -1;//turn right
		else
			return 1;//turn left
	}
	else
		return 0; // exactly aligned
}

am I overkilling with the two scenarios?

Thanks again
Scott
 




 8 Posts in Topic:
Algorithm to find the shortest rotation using degrees?
"m0rdred" <i  2006-10-22 22:27:06 
Re: Algorithm to find the shortest rotation using degrees?
"Jim Langston"   2006-10-22 23:58:02 
Re: Algorithm to find the shortest rotation using degrees?
Tom Plunket <gamedev@[  2006-10-25 18:27:15 
Re: Algorithm to find the shortest rotation using degrees?
"m0rdred" <i  2006-10-27 15:06:46 
Re: Algorithm to find the shortest rotation using degrees?
Tom Plunket <gamedev@[  2006-10-27 17:15:06 
Re: Algorithm to find the shortest rotation using degrees?
"m0rdred" <i  2006-10-27 22:12:01 
Re: Algorithm to find the shortest rotation using degrees?
nathan@[EMAIL PROTECTED]   2006-10-28 05:54:39 
Re: Algorithm to find the shortest rotation using degrees?
"m0rdred" <i  2006-10-27 22:18:54 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Wed Jul 9 4:43:01 CDT 2008.