delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/03/25/22:13:40

Message-ID: <33388E03.F47@abc.se>
Date: Wed, 26 Mar 1997 03:46:27 +0100
From: Kjell Franzen <kjell DOT franzen AT abc DOT se>
Reply-To: Kjell DOT Franzen AT abc DOT se
MIME-Version: 1.0
To: eab AT salnet DOT org
CC: djgpp AT delorie DOT com
Subject: Re: Newbie troubles with Sin and Cos
References: <TCPSMTP DOT 17 DOT 3 DOT 25 DOT -13 DOT 20 DOT 10 DOT 2778967005 DOT 292016 AT salnet DOT salnet DOT org>

eab AT salnet DOT org wrote:
> 
> > I'm trying to write a routine that spins a pixel around in a circle.
> > That works ok so far, except that the X and Y points are never next
> > to each other - I think I have narrowed it down to the results I am
> > getting from using COS and SIN.
> 
>   [snip]
> 
> > result = sin(theta);
> > printf ("Sin of %i is %f\n",theta,result);
> 
>   [snip]
> 
> > Am I using the wrong variable types to hold the results ?  Do I need
> > to do something special in DJGPP to get the magic numbers ?
> 
> This isn't specific to DJGPP, but applies to most programming
> languages--you need to convert the angle from degrees to radians,
> because that's what the trig functions take.  In radians, pi equals
> 180 degrees, so to convert it to radians, you multiply it by 180/PI.

That have to be PI/180 to be correct, no? If You multiply by 180/PI the
angle would be be about 57 times greater instead of 57 times smaller.
(1 radian equals about 57,3 degrees).

> This changes the line from your example to
> 
>   result = sin(theta*180/PI)
                       ^^^^^^ should be : PI/180
> 
> (PI is a predefined value in math.h)
> 
> > dberry AT dca DOT gov DOT au
> 
> Ethan
> "The world beneath us spins in circles,
>  And this life makes us twist and turn and sway,
>  But we were made for more than rhythm with no reason
>  By the One who moves with passion and with grace
>  As He dances over all that He has made."
>      --Steven Curtis Chapman
> This message sent via TRI-RIVERS INTERNET, Inc. - Salina, KS. !

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019