www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/03/25/20:30:00

From: eab AT salnet DOT org
Date: Tue, 25 Mar 1997 19:20:10 -0500
Message-ID: <TCPSMTP.17.3.25.-13.20.10.2778967005.292016@salnet.salnet.org>
Subject: Newbie troubles with Sin and Cos
To: djgpp AT delorie DOT com

> 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.
This changes the line from your example to

  result = sin(theta*180/PI)

(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