| www.delorie.com/archives/browse.cgi | search | 
| From: | no DOT spam DOT please AT thanks DOT com | 
| Newsgroups: | comp.os.msdos.djgpp | 
| Subject: | Re: Tank Movement | 
| Date: | 7 Oct 1998 01:48:15 GMT | 
| Organization: | Texas Instruments | 
| Lines: | 29 | 
| Message-ID: | <6veh8v$4cq$2@superb.csc.ti.com> | 
| References: | <36147a32 DOT 10039817 AT ct-news DOT iafrica DOT com> | 
| <6vebp7$sap$1 AT fir DOT prod DOT itd DOT earthlink DOT net> | |
| <6vegc7$4cq$1 AT superb DOT csc DOT ti DOT com> | |
| NNTP-Posting-Host: | lenny.dseg.ti.com | 
| Mime-Version: | 1.0 | 
| X-Trace: | superb.csc.ti.com 907724895 4506 172.25.38.136 (7 Oct 1998 01:48:15 GMT) | 
| X-Complaints-To: | abuse AT ti DOT com | 
| NNTP-Posting-Date: | 7 Oct 1998 01:48:15 GMT | 
| X-Newsreader: | knews 0.9.8 | 
| To: | djgpp AT delorie DOT com | 
| DJ-Gateway: | from newsgroup comp.os.msdos.djgpp | 
| Reply-To: | djgpp AT delorie DOT com | 
In article <6vegc7$4cq$1 AT superb DOT csc DOT ti DOT com>,
	no DOT spam DOT please AT thanks DOT com writes:
> A much easier approach - use atan2(), which takes care of the quadrant
> mapping for you, e.g.,
> 
> double dir_degrees(int x1, int y1, int y2, int x2)
> {
>  int v1, v2;
>  double dir;
>  v1 = y1 - y2;
>  v2 = x1 - x2;
>  dir = 57 * atan( v1, v2 );
                  ^
Oops, I forgot the 2!  Sorry.  Try
#define RAD2DEG 180.0/PI
  ....
  dir = RAD2DEG * atan2( v1, v2 );
Also, since atan2 (and atan) return a double, you might as well retain
the precision in the rad-to-deg conversion.  It doesn't cost you
anything.
>  return dir;
> }
Oops, I forgot the 2!
| webmaster | delorie software privacy | 
| Copyright © 2019 by DJ Delorie | Updated Jul 2019 |