Title: **Inverse trig functions**

Post by:**Jetfire** on **Apr 04, 2013, 11:40 pm**

Post by:

They locked this topic away in the arcives, so I'll just do this:

http://arduino.cc/forum/index.php?PHPSESSID=99fdf9fb9ed775fd5c50e3e70f03aec8&topic=41402.0

I need the <math.h> library and I can't find the .h and .ccp files.

Or if you could just tell me how to get the arc functions that would work too.

Thanks.

http://arduino.cc/forum/index.php?PHPSESSID=99fdf9fb9ed775fd5c50e3e70f03aec8&topic=41402.0

I need the <math.h> library and I can't find the .h and .ccp files.

Or if you could just tell me how to get the arc functions that would work too.

Thanks.

Title: **Re: Inverse trig functions**

Post by:**Jsut210** on **Apr 05, 2013, 12:21 am**

Post by:

This may help http://arduino.cc/forum/index.php/topic,44229.0.html

What happens if you just try something like:

What happens if you just try something like:

Code: [Select]

float invsin = asin(num);

Title: **Re: Inverse trig functions**

Post by:**codlink** on **Apr 05, 2013, 12:37 am**

Post by:

He's trying to tell you that the math library is already including in the IDE. And actually, you don't have to use a header to include it either. [ref]http://arduino.cc/en/Math/H

Here's another library if you need more complexity.

http://playground.arduino.cc/Main/ComplexMath

Here's another library if you need more complexity.

http://playground.arduino.cc/Main/ComplexMath

Title: **Re: Inverse trig functions**

Post by:**robtillaart** on **Apr 05, 2013, 08:31 pm**

Post by:

note that the asin() return radians

- http://www.nongnu.org/avr-libc/user-manual/group__avr__math.html -

*The returned value is in the range [-pi/2, pi/2] radians. A domain error occurs for arguments not in the range [-1, +1].*

- http://www.nongnu.org/avr-libc/user-manual/group__avr__math.html -

Title: **Re: Inverse trig functions**

Post by:**Jetfire** on **Apr 05, 2013, 09:54 pm**

Post by:

Ok cool

Rewrote my arcsin() as asin and that compiled fine.

Including the conversion formula for radians to degrees didn't work so well.

The value pi is apparently not included in the package.

Should I just use "3.14159265358979323846" or is there some other way?

Thanks

Rewrote my arcsin() as asin and that compiled fine.

Including the conversion formula for radians to degrees didn't work so well.

The value pi is apparently not included in the package.

Should I just use "3.14159265358979323846" or is there some other way?

Thanks

Title: **Re: Inverse trig functions**

Post by:**Jsut210** on **Apr 05, 2013, 11:16 pm**

Post by:

The value of Pi isn't included with math.h. You should just do something like:

Then you can just use the "PI" definition where needed.

Code: [Select]

#define PI 3.14.....

Then you can just use the "PI" definition where needed.

Title: **Re: Inverse trig functions**

Post by:**WizenedEE** on **Apr 06, 2013, 02:30 am**

Post by:

The value of Pi isn't included with math.h. You should just do something like:Code: [Select]

#define PI 3.14.....

Then you can just use the "PI" definition where needed.

Arduino.h already defines PI

Title: **Re: Inverse trig functions**

Post by:**Jsut210** on **Apr 06, 2013, 02:34 am**

Post by:

The value of Pi isn't included with math.h. You should just do something like:Code: [Select]

#define PI 3.14.....

Then you can just use the "PI" definition where needed.

Arduino.h already defines PI

Even Better

Title: **Re: Inverse trig functions**

Post by:**robtillaart** on **Apr 06, 2013, 01:06 pm**

Post by:

math.h does define: - http://www.nongnu.org/avr-libc/user-manual/group__avr__math.html -

#define M_PI 3.14159265358979323846 /* pi */

#define M_PI_2 1.57079632679489661923 /* pi/2 */

#define M_PI_4 0.78539816339744830962 /* pi/4 */

#define M_1_PI 0.31830988618379067154 /* 1/pi */

#define M_2_PI 0.63661977236758134308 /* 2/pi */

#define M_2_SQRTPI 1.12837916709551257390 /* 2/sqrt(pi) */

unfortunately math.h does not define 180/PI and PI/180 for radians <> degrees conversion

(windows calc)

#define M_180_PI 57,295779513082320876798154814105 /*180/pi */

#define M_PI_180 0,01745329251994329576923690768489 /* pi/180 */

// the arduino does only support about 7 digits of float precision so the above numbers are overkill (unless the arbitrary precision lib is used )

#define M_PI 3.14159265358979323846 /* pi */

#define M_PI_2 1.57079632679489661923 /* pi/2 */

#define M_PI_4 0.78539816339744830962 /* pi/4 */

#define M_1_PI 0.31830988618379067154 /* 1/pi */

#define M_2_PI 0.63661977236758134308 /* 2/pi */

#define M_2_SQRTPI 1.12837916709551257390 /* 2/sqrt(pi) */

unfortunately math.h does not define 180/PI and PI/180 for radians <> degrees conversion

(windows calc)

#define M_180_PI 57,295779513082320876798154814105 /*180/pi */

#define M_PI_180 0,01745329251994329576923690768489 /* pi/180 */

// the arduino does only support about 7 digits of float precision so the above numbers are overkill (unless the arbitrary precision lib is used )

Title: **Re: Inverse trig functions**

Post by:**Jetfire** on **Apr 06, 2013, 11:23 pm**

Post by:

The value of Pi isn't included with math.h. You should just do something like:Code: [Select]

#define PI 3.14.....

Then you can just use the "PI" definition where needed.

Arduino.h already defines PI

OK

I changed pi to PI and it compiled OK

I'm waiting for hardware to test it out.

Anyone know where I can get 20-25 servos for under $100?

Title: **Re: Inverse trig functions**

Post by:**PaulS** on **Apr 07, 2013, 04:29 pm**

Post by:

Quote

Anyone know where I can get 20-25 servos for under $100?

20 minus 25 is -5. You could send me 5 servos and $100, and you'd have -5 servos for $100.

Title: **Re: Inverse trig functions**

Post by:**Jsut210** on **Apr 07, 2013, 04:31 pm**

Post by:

These are about the cheapest servos you can get:

http://www.ebay.com/itm/Micro-9g-Mini-RC-Servo-for-Trex-450-Futaba-Hitec-HS-55-Align-GWS-JR-Walkera-Heli-/140922521530?pt=LH_DefaultDomain_0&hash=item20cfa307ba

Yep, straight from china. Keep in mind that you get what you pay for.

http://www.ebay.com/itm/Micro-9g-Mini-RC-Servo-for-Trex-450-Futaba-Hitec-HS-55-Align-GWS-JR-Walkera-Heli-/140922521530?pt=LH_DefaultDomain_0&hash=item20cfa307ba

Yep, straight from china. Keep in mind that you get what you pay for.