delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/10/25/16:02:55

From: Jonathan Foster <jgf1 AT ukc DOT ac DOT uk>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: Newbie seeks help with rotating triangle program
Date: 23 Oct 1997 07:06:48 GMT
Organization: University of Kent at Canterbury, England
Lines: 19
Message-ID: <62mt28$rc0$2p@195.26.68.19>
References: <19971015041101 DOT AAA17302 AT ladder01 DOT news DOT aol DOT com>
NNTP-Posting-Host: 195.26.68.19
Mime-Version: 1.0
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

Joshua Hab wrote:
> x=(RADIUS_LENGTH*(cos(theta/360*6.28)))+CENTER_X
                        ^^^^^^^^^

This is a problem with number types.  The fragment "theta/360" is
taking an "int theta" and dividing it by the integer 360.  The result
will be rounded to an _integer_ according to the ANSI C spec, and
because the answer is less than 1 this means the angle will always be
rounded to zero.

Try this:  "theta/360.0*6.28"  The "360.0" is now a _float_, so the
value of "theta" is made into a float.  This allows the division to 
give a fractional answer, and it should work.

-- 
   Jon Foster.

(1st Year Maths/Computer Science Student)

- Raw text -


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