2013-09-29 14:16:03 +02:00
|
|
|
//
|
2013-09-29 14:13:36 +02:00
|
|
|
// FILE: Complex.h
|
|
|
|
// AUTHOR: Rob Tillaart
|
2015-03-06 14:02:38 +01:00
|
|
|
// VERSION: 0.1.08
|
2013-09-29 14:13:36 +02:00
|
|
|
// PURPOSE: library for Complex math for Arduino
|
2013-09-29 14:22:21 +02:00
|
|
|
// URL: http://arduino.cc/playground/Main/ComplexMath
|
2013-09-29 14:16:03 +02:00
|
|
|
//
|
2013-09-29 14:13:36 +02:00
|
|
|
// Released to the public domain
|
|
|
|
//
|
|
|
|
|
|
|
|
#ifndef Complex_h
|
|
|
|
#define Complex_h
|
|
|
|
|
|
|
|
#if defined(ARDUINO) && ARDUINO >= 100
|
|
|
|
#include "Arduino.h"
|
|
|
|
#else
|
|
|
|
#include "WProgram.h"
|
|
|
|
#endif
|
|
|
|
|
2013-09-29 14:31:13 +02:00
|
|
|
#include "Printable.h"
|
|
|
|
|
2015-03-06 14:02:38 +01:00
|
|
|
#define COMPLEX_LIB_VERSION "0.1.08"
|
2013-09-29 14:27:38 +02:00
|
|
|
|
|
|
|
// five categories of functions can be switched per category
|
|
|
|
// by (un)commenting next lines.
|
2013-09-29 14:13:36 +02:00
|
|
|
|
2013-09-29 14:31:13 +02:00
|
|
|
#define COMPLEX_EXTENDED
|
|
|
|
#define COMPLEX_GONIO_1
|
|
|
|
#define COMPLEX_GONIO_2
|
|
|
|
#define COMPLEX_GONIO_3
|
|
|
|
#define COMPLEX_GONIO_4
|
|
|
|
|
|
|
|
class Complex: public Printable
|
2013-09-29 14:13:36 +02:00
|
|
|
{
|
|
|
|
public:
|
2015-03-06 10:41:34 +01:00
|
|
|
Complex(double r, double i) : re(r), im(i) {};
|
|
|
|
Complex(const Complex &c) : re(c.re), im(c.im) {};
|
|
|
|
Complex(double d) : re(d), im(0) {};
|
2013-09-29 14:16:03 +02:00
|
|
|
|
2015-03-06 10:41:34 +01:00
|
|
|
void set(double r, double i ) { re = r; im = i; };
|
|
|
|
double real() { return re; };
|
|
|
|
double imag() { return im; };
|
2013-09-29 14:16:03 +02:00
|
|
|
|
2015-03-06 10:41:34 +01:00
|
|
|
size_t printTo(Print& p) const;
|
2013-09-29 14:16:03 +02:00
|
|
|
|
2015-03-06 10:41:34 +01:00
|
|
|
void polar(const double, const double);
|
|
|
|
double phase() { return atan2(im, re); };
|
|
|
|
double modulus() { return hypot(re, im); };
|
|
|
|
// conjugate is the number mirrored in x-axis
|
|
|
|
Complex conjugate() { return Complex(re,-im); };
|
2013-09-29 14:31:13 +02:00
|
|
|
Complex reciprocal();
|
2013-09-29 14:16:03 +02:00
|
|
|
|
2015-03-06 10:41:34 +01:00
|
|
|
bool operator == (const Complex&);
|
|
|
|
bool operator != (const Complex&);
|
2013-09-29 14:16:03 +02:00
|
|
|
|
|
|
|
Complex operator - (); // negation
|
|
|
|
|
2015-03-06 10:41:34 +01:00
|
|
|
Complex operator + (const Complex&);
|
|
|
|
Complex operator - (const Complex&);
|
|
|
|
Complex operator * (const Complex&);
|
|
|
|
Complex operator / (const Complex&);
|
2013-09-29 14:13:36 +02:00
|
|
|
|
2015-03-06 10:41:34 +01:00
|
|
|
Complex& operator += (const Complex&);
|
|
|
|
Complex& operator -= (const Complex&);
|
|
|
|
Complex& operator *= (const Complex&);
|
|
|
|
Complex& operator /= (const Complex&);
|
2013-09-29 14:16:03 +02:00
|
|
|
|
2013-09-29 14:27:38 +02:00
|
|
|
#ifdef COMPLEX_EXTENDED
|
2013-09-29 14:31:13 +02:00
|
|
|
Complex c_sqrt();
|
|
|
|
Complex c_sqr();
|
|
|
|
Complex c_exp();
|
|
|
|
Complex c_log();
|
|
|
|
Complex c_log10();
|
2015-03-06 14:02:38 +01:00
|
|
|
Complex c_pow(const Complex &);
|
|
|
|
Complex c_logn(const Complex &);
|
2013-09-29 14:27:38 +02:00
|
|
|
#endif
|
2013-09-29 14:16:03 +02:00
|
|
|
|
2013-09-29 14:27:38 +02:00
|
|
|
#ifdef COMPLEX_GONIO_1
|
2013-09-29 14:31:13 +02:00
|
|
|
Complex c_sin();
|
|
|
|
Complex c_cos();
|
|
|
|
Complex c_tan();
|
|
|
|
Complex c_asin();
|
|
|
|
Complex c_acos();
|
|
|
|
Complex c_atan();
|
2013-09-29 14:27:38 +02:00
|
|
|
#endif
|
2013-09-29 14:16:03 +02:00
|
|
|
|
2013-09-29 14:27:38 +02:00
|
|
|
#ifdef COMPLEX_GONIO_2
|
2013-09-29 14:31:13 +02:00
|
|
|
Complex c_csc();
|
|
|
|
Complex c_sec();
|
|
|
|
Complex c_cot();
|
|
|
|
Complex c_acsc();
|
|
|
|
Complex c_asec();
|
|
|
|
Complex c_acot();
|
2013-09-29 14:27:38 +02:00
|
|
|
#endif
|
2013-09-29 14:16:03 +02:00
|
|
|
|
2013-09-29 14:27:38 +02:00
|
|
|
#ifdef COMPLEX_GONIO_3
|
2013-09-29 14:31:13 +02:00
|
|
|
Complex c_sinh();
|
|
|
|
Complex c_cosh();
|
|
|
|
Complex c_tanh();
|
|
|
|
Complex c_asinh();
|
|
|
|
Complex c_acosh();
|
|
|
|
Complex c_atanh();
|
2013-09-29 14:27:38 +02:00
|
|
|
#endif
|
2013-09-29 14:16:03 +02:00
|
|
|
|
2013-09-29 14:27:38 +02:00
|
|
|
#ifdef COMPLEX_GONIO_4
|
2013-09-29 14:31:13 +02:00
|
|
|
Complex c_csch();
|
|
|
|
Complex c_sech();
|
|
|
|
Complex c_coth();
|
|
|
|
Complex c_acsch();
|
|
|
|
Complex c_asech();
|
|
|
|
Complex c_acoth();
|
2013-09-29 14:27:38 +02:00
|
|
|
#endif
|
2013-09-29 14:16:03 +02:00
|
|
|
|
2015-03-06 10:41:34 +01:00
|
|
|
protected:
|
2013-09-29 14:31:13 +02:00
|
|
|
double re;
|
|
|
|
double im;
|
2015-03-06 10:41:34 +01:00
|
|
|
|
|
|
|
Complex gonioHelper1(const byte);
|
|
|
|
Complex gonioHelper2(const byte);
|
2013-09-29 14:13:36 +02:00
|
|
|
};
|
2013-09-29 14:22:21 +02:00
|
|
|
|
2015-03-06 10:41:34 +01:00
|
|
|
static Complex one(1, 0);
|
2013-09-29 14:31:13 +02:00
|
|
|
|
2013-09-29 14:13:36 +02:00
|
|
|
#endif
|
|
|
|
// --- END OF FILE ---
|