GIDForums  

Go Back   GIDForums > Computer Programming Forums > C++ Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 21-Nov-2008, 09:32
Cherry65 Cherry65 is offline
New Member
 
Join Date: Nov 2008
Posts: 1
Cherry65 is on a distinguished road

Rewrite the function atan2f


Im doing some exercises from a book, and in one of them i have to rewrite the function atan2f. First, i wanted to explore a bit about this function, and while doing this i noticed that the results given by this function differed from the ones given in the book. For example, the book says that atan2f(4,2) = 63.46(degrees) and when i do this:
CPP / C++ / C Code:
#include <iostream>
#include <cmath>
using namespace std;

int main()
{
	cout << atan2f(4,2) << endl;
	system("PAUSE");
}
the result is 1.1 pi, that is 198 degrees. When i check this on a sheet of paper i realise that the result given by the book is the correct one. Whats wrong with this?

Maybe i misunderstood the excercise. This is the exercise:
Code:
Using atanf, write a function with the following prototype: float MyArcTangent(float y, float x); This function should examine the signs of coordinates of the point (x, y) and return the correct angle based on what quadrant the point lies in. Test your function with the following points: (2,4), (-1,5), (-6,-4), (4, -6). You sould get the following results: MyArcTangent (4, 2) = 63.4671 MyArcTangent (5, -1) = 101.27 MyArcTangent (-4, -6) = 213.707 MyArcTangent (-6, 4) = -56.3385 Press any key to continue Now that you have written the function yourself, you should know that the C++ standard math library already includes a function that does what your function does. Its prototype is: float atan2f(float y, float x);
Last edited by LuciWiz : 21-Nov-2008 at 09:35. Reason: Please insert your C++ code between [cpp] & [/cpp] tags
  #2  
Old 21-Nov-2008, 11:51
Blake's Avatar
Blake Blake is offline
Member
 
Join Date: Nov 2005
Posts: 255
Blake is a jewel in the roughBlake is a jewel in the rough

Re: Rewrite the function atan2f


The return value of 1.1 does not mean 1.1pi. It mean 1.1 radians. Multiply that by 180/pi to get degrees, and your answer will agree with the answer in the book.
__________________
www.blake-foster.com
  #3  
Old 24-Nov-2008, 21:28
Peter_APIIT Peter_APIIT is offline
Regular Member
 
Join Date: May 2007
Location: Malaysia
Posts: 545
Peter_APIIT can only hope to improve

Re: Rewrite the function atan2f


How to code this function ? What this function does ?
  #4  
Old 24-Nov-2008, 21:29
Blake's Avatar
Blake Blake is offline
Member
 
Join Date: Nov 2005
Posts: 255
Blake is a jewel in the roughBlake is a jewel in the rough

Re: Rewrite the function atan2f


http://en.wikipedia.org/wiki/Atan2
__________________
www.blake-foster.com
  #5  
Old 25-Nov-2008, 02:32
Peter_APIIT Peter_APIIT is offline
Regular Member
 
Join Date: May 2007
Location: Malaysia
Posts: 545
Peter_APIIT can only hope to improve

Re: Rewrite the function atan2f


Thanks for your help..
 
 

Recent GIDBlogReview: Gel laptop cooling pad by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
run script command on ns2.26 newbie06 Computer Software Forum - Linux 65 19-Aug-2009 08:50
Airport Log program using 3D linked List : problem reading from file batrsau C Programming Language 11 29-Feb-2008 08:44
Flex and bison coding lucky88star C++ Forum 5 24-Dec-2007 12:57
Need Help with input files. Efferus C++ Forum 2 24-Nov-2007 17:19
[Include] Doubly-linked List dsmith C Programming Language 6 14-Apr-2006 14:12

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 23:35.


vBulletin, Copyright © 2000 - 2009, Jelsoft Enterprises Ltd.