scifir-units 2.0.0
scifir-units is a library of units of measurement, angles, coordinates, fields, and related data, all lightweight, that help in the development of scientific software and scientific machines
Loading...
Searching...
No Matches
Classes | Namespaces | Functions
angle.hpp File Reference
#include "../units/constants.hpp"
#include "../util/is_number.hpp"
#include "../units/scalar_unit.hpp"
#include <cmath>
#include <numbers>
#include <string>
Include dependency graph for angle.hpp:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

class  scifir::angle
 Class that allows to work with angles. Each angle sizes 4 bytes. Initialization string example: "20°". More...
 

Namespaces

namespace  scifir
 The namespace scifir contains all scifir-units, excepting the string literals, which are outside.
 

Functions

float scifir::radian_to_degree (float x)
 Converts a radian to degree.
 
float scifir::gradian_to_degree (float x)
 
float scifir::turn_to_degree (float x)
 
float scifir::degree_to_radian (float x)
 Converts a degree to a radian.
 
float scifir::gradian_to_radian (float x)
 
float scifir::turn_to_radian (float x)
 
float scifir::degree_to_gradian (float x)
 
float scifir::radian_to_gradian (float x)
 
float scifir::turn_to_gradian (float x)
 
float scifir::degree_to_turn (float x)
 
float scifir::radian_to_turn (float x)
 
float scifir::gradian_to_turn (float x)
 
string scifir::to_string (const angle &x)
 Converts an angle to their string representation.
 
bool scifir::is_angle (const string &init_angle)
 Checks if some string is an initialization string of an angle.
 
bool scifir::parallel (const angle &x, const angle &y)
 Checks if two angles in a 2D correspond to parallel lines (or parallel vectors).
 
bool scifir::orthogonal (const angle &x, const angle &y)
 Checks if two angles in a 2D correspond to orthogonal lines (or orthogonal vectors).
 
angle scifir::sqrt (const angle &x)
 Calculates the square root of the angle x and returns that new angle.
 
angle scifir::sqrt_nth (const angle &x, int index)
 Calculates the nth root of the angle x and returns that new angle.
 
float scifir::sin (const angle &x)
 Calculates the sin of angle x. It uses the sin() function of the standard library of C++, the difference is that angle is in degrees, not in radians.
 
float scifir::cos (const angle &x)
 Calculates the cos of angle x. It uses the cos() function of the standard library of C++, the difference is that angle is in degrees, not in radians.
 
float scifir::tan (const angle &x)
 Calculates the tan of angle x. It uses the tan() function of the standard library of C++, the difference is that angle is in degrees, not in radians.
 
angle scifir::asin (float x)
 Calculates the asin of some value x and returns the result as angle in degrees.
 
angle scifir::acos (float x)
 Calculates the acos of some value x and returns the result as angle in degrees.
 
angle scifir::atan (float x)
 Calculates the atan of some value x and returns the result as angle in degrees.
 
angle scifir::atan2 (float y, float x)
 
float scifir::sinh (const angle &x)
 Calculates the sinh of angle x. It uses the sinh() function of the standard library of C++, the difference is that angle is in degrees, not in radians.
 
float scifir::cosh (const angle &x)
 Calculates the cosh of angle x. It uses the cosh() function of the standard library of C++, the difference is that angle is in degrees, not in radians.
 
float scifir::tanh (const angle &x)
 Calculates the tanh of angle x. It uses the tanh() function of the standard library of C++, the difference is that angle is in degrees, not in radians.
 
angle scifir::asinh (float x)
 Calculates the asinh of some value x and returns the result as angle in degrees.
 
angle scifir::acosh (float x)
 Calculates the acosh of some value x and returns the result as angle in degrees.
 
angle scifir::atanh (float x)
 Calculates the atanh of some value x and returns the result as angle in degrees.
 
float scifir::asin_degree (float x)
 Calculates the asin receiving x in degrees. It uses the asin() function of the standard library of C++, but the difference is that the argument is in degrees, not in radians.
 
float scifir::acos_degree (float x)
 Calculates the acos receiving x in degrees. It uses the acos() function of the standard library of C++, but the difference is that the argument is in degrees, not in radians.
 
float scifir::atan_degree (float x)
 Calculates the atan receiving x in degrees. It uses the atan() function of the standard library of C++, but the difference is that the argument is in degrees, not in radians.
 
float scifir::asinh_degree (float x)
 Calculates the asinh receiving x in degrees. It uses the asinh() function of the standard library of C++, but the difference is that the argument is in degrees, not in radians.
 
float scifir::acosh_degree (float x)
 Calculates the acosh receiving x in degrees. It uses the acosh() function of the standard library of C++, but the difference is that the argument is in degrees, not in radians.
 
float scifir::atanh_degree (float x)
 Calculates the atanh receiving x in degrees. It uses the atanh() function of the standard library of C++, but the difference is that the argument is in degrees, not in radians.
 
template<typename T , typename = typename enable_if<scifir::is_number<T>::value>::type>
scifir::angle operator+ (T x, const scifir::angle &y)
 Creates a new angle as the sum of a numeric type with the value of this angle.
 
template<typename T , typename = typename enable_if<scifir::is_number<T>::value>::type>
scifir::angle operator- (T x, const scifir::angle &y)
 Creates a new angle as the substraction of the numeric type with the value of this angle.
 
template<typename T , typename = typename enable_if<scifir::is_number<T>::value>::type>
scifir::angle operator* (T x, const scifir::angle &y)
 Creates a new angle as the multiplication of a numeric type with the value of this angle.
 
template<typename T , typename = typename enable_if<scifir::is_number<T>::value>::type>
scifir::angle operator/ (T x, const scifir::angle &y)
 Creates a new angle as the division of the value of this angle with the numeric type.
 
template<typename T , typename = typename enable_if<scifir::is_number<T>::value>::type>
scifir::angle operator^ (T x, const scifir::angle &y)
 Creates a new angle as the power of a numeric type with the value of this angle.
 
template<typename T , typename = typename enable_if<scifir::is_number<T>::value>::type>
bool operator== (T x, const scifir::angle &y)
 Checks if the value of angle y is equal to a numeric type x.
 
template<typename T , typename = typename enable_if<scifir::is_number<T>::value>::type>
bool operator!= (T x, const scifir::angle &y)
 Checks if the value of angle y is not equal to a numeric type x.
 
template<typename T , typename = typename enable_if<scifir::is_number<T>::value>::type>
bool operator< (T x, const scifir::angle &y)
 Checks if the value of angle y is greather to a numeric type x.
 
template<typename T , typename = typename enable_if<scifir::is_number<T>::value>::type>
bool operator> (T x, const scifir::angle &y)
 Checks if the value of angle y is lower to a numeric type x.
 
template<typename T , typename = typename enable_if<scifir::is_number<T>::value>::type>
bool operator<= (T x, const scifir::angle &y)
 Checks if the value of angle y is equal or greather than a numeric type x.
 
template<typename T , typename = typename enable_if<scifir::is_number<T>::value>::type>
bool operator>= (T x, const scifir::angle &y)
 Checks if the value of angle y is lower or equal than a numeric type x.
 
template<typename T , typename = typename enable_if<scifir::is_number<T>::value>::type>
bool operator== (const scifir::angle &y, T x)
 Checks if the value of angle y is equal to a numeric type x.
 
template<typename T , typename = typename enable_if<scifir::is_number<T>::value>::type>
bool operator!= (const scifir::angle &y, T x)
 Checks if the value of angle y is not equal to a numeric type x.
 
template<typename T , typename = typename enable_if<scifir::is_number<T>::value>::type>
bool operator< (const scifir::angle &y, T x)
 Checks if the value of angle y is lower to a numeric type x.
 
template<typename T , typename = typename enable_if<scifir::is_number<T>::value>::type>
bool operator> (const scifir::angle &y, T x)
 Checks if the value of angle y is greather to a numeric type x.
 
template<typename T , typename = typename enable_if<scifir::is_number<T>::value>::type>
bool operator<= (const scifir::angle &y, T x)
 Checks if the value of angle y is lower or equal than a numeric type x.
 
template<typename T , typename = typename enable_if<scifir::is_number<T>::value>::type>
bool operator>= (const scifir::angle &y, T x)
 Checks if the value of angle y is equal or greather than a numeric type x.
 
bool operator== (const scifir::angle &x, const scifir::angle &y)
 Checks if two angles have equal value.
 
bool operator!= (const scifir::angle &x, const scifir::angle &y)
 Checks if two angles have not equal value.
 
bool operator< (const scifir::angle &x, const scifir::angle &y)
 Checks if the value of angle x is lower than the value of angle y.
 
bool operator> (const scifir::angle &x, const scifir::angle &y)
 Checks if the value of angle x is greather than the value of angle y.
 
bool operator<= (const scifir::angle &x, const scifir::angle &y)
 Checks if the value of angle x is lower or equal than the value of angle y.
 
bool operator>= (const scifir::angle &x, const scifir::angle &y)
 Checks if the value of angle x is equal or greather than the value of angle y.
 
bool operator== (const scifir::angle &x, const string &init_angle)
 Checks if the angle x is equal than the angle initialized with the initialization string of angle init_angle.
 
bool operator!= (const scifir::angle &x, const string &init_angle)
 Checks if the angle x is not equal than the angle initialized with the initialization string of angle init_angle.
 
bool operator== (const string &init_angle, const scifir::angle &x)
 Checks if the angle x is equal than the angle initialized with the initialization string of angle init_angle.
 
bool operator!= (const string &init_angle, const scifir::angle &x)
 Checks if the angle x is not equal than the angle initialized with the initialization string of angle init_angle.
 
void operator+= (string &x, const scifir::angle &y)
 Concatenates to string x the string representation of angle y.
 
string operator+ (const string &x, const scifir::angle &y)
 Concatenates the string x with the string representation of angle y into a new string.
 
string operator+ (const scifir::angle &y, const string &x)
 Concatenates the string x with the string representation of angle y into a new string.
 
ostream & operator<< (ostream &os, const scifir::angle &x)
 Sends the string representation of angle x to an output stream.
 
istream & operator>> (istream &is, scifir::angle &x)
 Initializes an angle with an initialization string obtained from an input stream.
 

Function Documentation

◆ operator!=() [1/5]

bool operator!= ( const scifir::angle x,
const scifir::angle y 
)

Checks if two angles have not equal value.

Definition at line 504 of file angle.cpp.

505{
506 return !(x == y);
507}

◆ operator!=() [2/5]

bool operator!= ( const scifir::angle x,
const string &  init_angle 
)

Checks if the angle x is not equal than the angle initialized with the initialization string of angle init_angle.

Definition at line 549 of file angle.cpp.

550{
551 return !(x == init_angle);
552}

◆ operator!=() [3/5]

template<typename T , typename = typename enable_if<scifir::is_number<T>::value>::type>
bool operator!= ( const scifir::angle y,
x 
)

Checks if the value of angle y is not equal to a numeric type x.

Definition at line 346 of file angle.hpp.

347{
348 return (x != y.get_value());
349}
const float & get_value() const
Gets the value of the angle, in degrees.
Definition angle.hpp:102

◆ operator!=() [4/5]

bool operator!= ( const string &  init_angle,
const scifir::angle x 
)

Checks if the angle x is not equal than the angle initialized with the initialization string of angle init_angle.

Definition at line 560 of file angle.cpp.

561{
562 return !(init_angle == x);
563}

◆ operator!=() [5/5]

template<typename T , typename = typename enable_if<scifir::is_number<T>::value>::type>
bool operator!= ( x,
const scifir::angle y 
)

Checks if the value of angle y is not equal to a numeric type x.

Definition at line 310 of file angle.hpp.

311{
312 return (x != y.get_value());
313}

◆ operator*()

template<typename T , typename = typename enable_if<scifir::is_number<T>::value>::type>
scifir::angle operator* ( x,
const scifir::angle y 
)

Creates a new angle as the multiplication of a numeric type with the value of this angle.

Definition at line 286 of file angle.hpp.

287{
288 return scifir::angle(x * y.get_value());
289}
Class that allows to work with angles. Each angle sizes 4 bytes. Initialization string example: "20°"...
Definition angle.hpp:77

◆ operator+() [1/3]

string operator+ ( const scifir::angle y,
const string &  x 
)

Concatenates the string x with the string representation of angle y into a new string.

Definition at line 580 of file angle.cpp.

581{
582 ostringstream output;
583 output << y;
584 output << x;
585 return output.str();
586}

◆ operator+() [2/3]

string operator+ ( const string &  x,
const scifir::angle y 
)

Concatenates the string x with the string representation of angle y into a new string.

Definition at line 572 of file angle.cpp.

573{
574 ostringstream output;
575 output << x;
576 output << y;
577 return output.str();
578}

◆ operator+() [3/3]

template<typename T , typename = typename enable_if<scifir::is_number<T>::value>::type>
scifir::angle operator+ ( x,
const scifir::angle y 
)

Creates a new angle as the sum of a numeric type with the value of this angle.

Definition at line 274 of file angle.hpp.

275{
276 return scifir::angle(x + y.get_value());
277}

◆ operator+=()

void operator+= ( string &  x,
const scifir::angle y 
)

Concatenates to string x the string representation of angle y.

Definition at line 565 of file angle.cpp.

566{
567 ostringstream output;
568 output << y;
569 x += output.str();
570}

◆ operator-()

template<typename T , typename = typename enable_if<scifir::is_number<T>::value>::type>
scifir::angle operator- ( x,
const scifir::angle y 
)

Creates a new angle as the substraction of the numeric type with the value of this angle.

Definition at line 280 of file angle.hpp.

281{
282 return scifir::angle(x - y.get_value());
283}

◆ operator/()

template<typename T , typename = typename enable_if<scifir::is_number<T>::value>::type>
scifir::angle operator/ ( x,
const scifir::angle y 
)

Creates a new angle as the division of the value of this angle with the numeric type.

Definition at line 292 of file angle.hpp.

293{
294 return scifir::angle(x / y.get_value());
295}

◆ operator<() [1/3]

bool operator< ( const scifir::angle x,
const scifir::angle y 
)

Checks if the value of angle x is lower than the value of angle y.

Definition at line 509 of file angle.cpp.

510{
511 if(x.get_value() < y.get_value())
512 {
513 return true;
514 }
515 else
516 {
517 return false;
518 }
519}

◆ operator<() [2/3]

template<typename T , typename = typename enable_if<scifir::is_number<T>::value>::type>
bool operator< ( const scifir::angle y,
x 
)

Checks if the value of angle y is lower to a numeric type x.

Definition at line 352 of file angle.hpp.

353{
354 return (y.get_value() < x);
355}

◆ operator<() [3/3]

template<typename T , typename = typename enable_if<scifir::is_number<T>::value>::type>
bool operator< ( x,
const scifir::angle y 
)

Checks if the value of angle y is greather to a numeric type x.

Definition at line 316 of file angle.hpp.

317{
318 return (x < y.get_value());
319}

◆ operator<<()

ostream & operator<< ( ostream &  os,
const scifir::angle x 
)

Sends the string representation of angle x to an output stream.

Definition at line 588 of file angle.cpp.

589{
590 return os << to_string(x);
591}
string to_string(const aid &x)
Creates a string representation of aid, it's for aid equivalent to the display() function of aid.
Definition aid.cpp:582

◆ operator<=() [1/3]

bool operator<= ( const scifir::angle x,
const scifir::angle y 
)

Checks if the value of angle x is lower or equal than the value of angle y.

Definition at line 533 of file angle.cpp.

534{
535 return !(x > y);
536}

◆ operator<=() [2/3]

template<typename T , typename = typename enable_if<scifir::is_number<T>::value>::type>
bool operator<= ( const scifir::angle y,
x 
)

Checks if the value of angle y is lower or equal than a numeric type x.

Definition at line 364 of file angle.hpp.

365{
366 return (y.get_value() <= x);
367}

◆ operator<=() [3/3]

template<typename T , typename = typename enable_if<scifir::is_number<T>::value>::type>
bool operator<= ( x,
const scifir::angle y 
)

Checks if the value of angle y is equal or greather than a numeric type x.

Definition at line 328 of file angle.hpp.

329{
330 return (x <= y.get_value());
331}

◆ operator==() [1/5]

bool operator== ( const scifir::angle x,
const scifir::angle y 
)

Checks if two angles have equal value.

Definition at line 492 of file angle.cpp.

493{
494 if(x.get_value() == y.get_value())
495 {
496 return true;
497 }
498 else
499 {
500 return false;
501 }
502}

◆ operator==() [2/5]

bool operator== ( const scifir::angle x,
const string &  init_angle 
)

Checks if the angle x is equal than the angle initialized with the initialization string of angle init_angle.

Definition at line 543 of file angle.cpp.

544{
545 scifir::angle y = scifir::angle(init_angle);
546 return (x == y);
547}

◆ operator==() [3/5]

template<typename T , typename = typename enable_if<scifir::is_number<T>::value>::type>
bool operator== ( const scifir::angle y,
x 
)

Checks if the value of angle y is equal to a numeric type x.

Definition at line 340 of file angle.hpp.

341{
342 return (x == y.get_value());
343}

◆ operator==() [4/5]

bool operator== ( const string &  init_angle,
const scifir::angle x 
)

Checks if the angle x is equal than the angle initialized with the initialization string of angle init_angle.

Definition at line 554 of file angle.cpp.

555{
556 scifir::angle y = scifir::angle(init_angle);
557 return (x == y);
558}

◆ operator==() [5/5]

template<typename T , typename = typename enable_if<scifir::is_number<T>::value>::type>
bool operator== ( x,
const scifir::angle y 
)

Checks if the value of angle y is equal to a numeric type x.

Definition at line 304 of file angle.hpp.

305{
306 return (x == y.get_value());
307}

◆ operator>() [1/3]

bool operator> ( const scifir::angle x,
const scifir::angle y 
)

Checks if the value of angle x is greather than the value of angle y.

Definition at line 521 of file angle.cpp.

522{
523 if(x.get_value() > y.get_value())
524 {
525 return true;
526 }
527 else
528 {
529 return false;
530 }
531}

◆ operator>() [2/3]

template<typename T , typename = typename enable_if<scifir::is_number<T>::value>::type>
bool operator> ( const scifir::angle y,
x 
)

Checks if the value of angle y is greather to a numeric type x.

Definition at line 358 of file angle.hpp.

359{
360 return (y.get_value() > x);
361}

◆ operator>() [3/3]

template<typename T , typename = typename enable_if<scifir::is_number<T>::value>::type>
bool operator> ( x,
const scifir::angle y 
)

Checks if the value of angle y is lower to a numeric type x.

Definition at line 322 of file angle.hpp.

323{
324 return (x > y.get_value());
325}

◆ operator>=() [1/3]

bool operator>= ( const scifir::angle x,
const scifir::angle y 
)

Checks if the value of angle x is equal or greather than the value of angle y.

Definition at line 538 of file angle.cpp.

539{
540 return !(x < y);
541}

◆ operator>=() [2/3]

template<typename T , typename = typename enable_if<scifir::is_number<T>::value>::type>
bool operator>= ( const scifir::angle y,
x 
)

Checks if the value of angle y is equal or greather than a numeric type x.

Definition at line 370 of file angle.hpp.

371{
372 return (y.get_value() >= x);
373}

◆ operator>=() [3/3]

template<typename T , typename = typename enable_if<scifir::is_number<T>::value>::type>
bool operator>= ( x,
const scifir::angle y 
)

Checks if the value of angle y is lower or equal than a numeric type x.

Definition at line 334 of file angle.hpp.

335{
336 return (x >= y.get_value());
337}

◆ operator>>()

istream & operator>> ( istream &  is,
scifir::angle x 
)

Initializes an angle with an initialization string obtained from an input stream.

Definition at line 593 of file angle.cpp.

594{
595 char a[256];
596 is.getline(a, 256);
597 string b(a);
598 boost::trim(b);
599 x = scifir::angle(b);
600 return is;
601}

◆ operator^()

template<typename T , typename = typename enable_if<scifir::is_number<T>::value>::type>
scifir::angle operator^ ( x,
const scifir::angle y 
)

Creates a new angle as the power of a numeric type with the value of this angle.

Definition at line 298 of file angle.hpp.

299{
300 return scifir::angle(pow(x, y.get_value()));
301}
scalar_unit pow(const scalar_unit &x, int exponent)
Exponentiates a scalar_unit to some numeric type, the dimensions are also exponentiated.