View unanswered posts | View active topics It is currently Sat Aug 27, 2016 12:39 am

 Page 1 of 1 [ 4 posts ]
 Print view Previous topic | Next topic
asin returns null value
Author Message
Rookie

Joined: Sun Mar 02, 2008 9:41 am
Posts: 25
asin returns null value
Hi,

I am trying to use asin to find out the degrees of an angle.
I have the following code but it always return 0.
double degreesToTurn;
degreesToTurn = asin(30);

Would anyone have any ideas why?

I have also try the sin function sothen i could pass the result to asin.

They both return 0.

Regards,
Giannis

Tue Mar 04, 2008 4:59 pm
Creator

Joined: Fri Feb 09, 2007 9:21 am
Posts: 616

The input value to "asin" needs to be in the range "-1 to +1". Otherwise the result is undefined. You're using 30 as the input!

It sounds like you're really wanting to turn an angle in radians (i.e. value 0 to 2*PI) to degrees (i.e. value 0 to 360). This is not what asin does!! Use the following formula for this conversion.

 Code:int degrees;degrees = 360 * (radians / (2 * PI));degrees %= 360;

Tue Mar 04, 2008 5:50 pm
Rookie

Joined: Sun Mar 02, 2008 9:41 am
Posts: 25
Hi
Hi,

I will try this but I have another question since i am completely new to C.

I am trying to do the following:

int i = 20;
int x = 30;

double w = i / x;

And I am not getting the same result.
Couldyou let me know why please?

Regards,
Giannis

Tue Mar 04, 2008 5:59 pm
Creator

Joined: Fri Feb 09, 2007 9:21 am
Posts: 616
Re: Hi
 giannisAPI wrote:Hi,int i = 20;int x = 30;double w = i / x;And I am not getting the same result.

C, and consequently ROBOTC, has some funny rules about calculation precisions and number bases. In the above 'i' and 'x' are both 'int' so "i / x' will be calculated using 'int' arithmetic and will result in '0'. The int value '0' will be converted to a 'float' and stored in 'w'.

You probably thought the result should be 0.66667 and were surprised with the zero value.

If you changed to
 Code:w = i / (float) x;

then you would get the fractional result. Because the cast of '(float)' applies to 'x' and then the calculation is performed with 'float' precision.

Tue Mar 04, 2008 7:59 pm
Display posts from previous:  Sort by
 Page 1 of 1 [ 4 posts ]

#### Who is online

Users browsing this forum: No registered users and 1 guest

 You cannot post new topics in this forumYou cannot reply to topics in this forumYou cannot edit your posts in this forumYou cannot delete your posts in this forumYou cannot post attachments in this forum

Search for:
 Jump to:  Select a forum ------------------ ROBOTC Applications    ROBOTC for LEGO MINDSTORMS       Third-party sensors    ROBOTC for CORTEX & PIC    ROBOTC for VEX IQ    ROBOTC for Arduino    Robot Virtual Worlds    Multi-Robot Communications    Issues and Bugs Competitions & Partners    Mini Urban Challenge    CS2N Robot Virtual Worlds Competitions       VEX Skyrise Competition 2014-2015       VEX Toss Up 2013-2014       FTC Block Party! 2013-2014    Competitions using VEX - BEST, TSA, VEX, and RoboFest!    FTC Programming    RoboCup Junior and Other ROBOT Competitions Virtual Brick Robotics Discussions    General Discussions    Project Discussions Off-Topic ROBOTC Forum & ROBOTC.net Suggestions/Feedback    ROBOTC Forums Suggestions/Comments    ROBOTC.net Suggestions/Comments       NXT Programming: Tips for Beginning with ROBOTC       VEX Programming: Tips for Beginning with ROBOTC    2013 Robotics Summer Of Learning       VEX Toss Up Programming Challenge       FTC Ring It Up! Programming Challenge    International Forums       Spanish Forums          ROBOTC for MINDSTORMS          ROBOTC for VEX       French Forums          ROBOTC pour Mindstorms          ROBOTC pour IFI VEX       Japanese Forums （日本語のフォーラム）       German Forums    2015 Spring Carnival Event    PLTW (Project Lead The Way)    Robotics Merit Badge    2014 Robotics Academy Summer of Learning