#include <Magnum/Math/Complex.h>
template<class T>
Complex class
Complex number.
Template parameters | |
---|---|
T | Data type |
Represents 2D rotation. Usually denoted as the following in equations, with being the real() part and the imaginary() part:
See 2D and 3D transformations for brief introduction.
Public types
- using Type = T
- Underlying data type.
Public static functions
Constructors, destructors, conversion operators
- Complex() constexpr noexcept
- Default constructor.
- Complex(IdentityInitT) explicit constexpr noexcept
- Identity constructor.
- Complex(ZeroInitT) explicit constexpr noexcept
- Construct zero-initialized complex number.
-
Complex(Magnum::
NoInitT) explicit noexcept - Construct without initializing the contents.
- Complex(T real, T imaginary) constexpr noexcept
- Construct a complex number from real and imaginary part.
- Complex(const Vector2<T>& vector) explicit constexpr noexcept
- Construct a complex number from a vector.
-
template<class U>Complex(const Complex<U>& other) explicit constexpr noexcept
- Construct a complex number from another of different type.
-
template<class U, class = decltype(Implementation::ComplexConverter<T, U>::from(std::Complex(const U& other) explicit constexpr
declval<U>()))> - Construct a complex number from external representation.
-
template<class U, class = decltype(Implementation::ComplexConverter<T, U>::to(std::operator U() const explicit constexpr
declval<Complex<T>>()))> - Convert the complex number to external representation.
- operator Vector2<T>() const explicit constexpr
- Convert a complex number to vector.
Public functions
- auto data() -> T*
- Raw data.
- auto data() const -> const T*
- auto operator==(const Complex<T>& other) const -> bool
- Equality comparison.
- auto operator!=(const Complex<T>& other) const -> bool
- Non-equality comparison.
- auto isNormalized() const -> bool
- Whether the complex number is normalized.
- auto real() -> T&
- Real part ( )
- auto real() const -> T constexpr
- auto imaginary() -> T&
- Imaginary part ( )
- auto imaginary() const -> T constexpr
- auto angle() const -> Rad<T>
- Rotation angle of a complex number.
- auto toMatrix() const -> Matrix2x2<T>
- Convert a complex number to a rotation matrix.
- auto operator+() const -> Complex<T> new in Git master
- Promotion.
- auto operator+=(const Complex<T>& other) -> Complex<T>&
- Add a complex number and assign.
- auto operator+(const Complex<T>& other) const -> Complex<T>
- Add a complex number.
- auto operator-() const -> Complex<T>
- Negated complex number.
- auto operator-=(const Complex<T>& other) -> Complex<T>&
- Subtract a complex number and assign.
- auto operator-(const Complex<T>& other) const -> Complex<T>
- Subtract a complex number.
- auto operator*=(T scalar) -> Complex<T>&
- Multiply with a scalar and assign.
- auto operator*=(const Vector2<T>& vector) -> Complex<T>&
- Multiply with a vector and assign.
- auto operator*(T scalar) const -> Complex<T>
- Multiply with a scalar.
- auto operator*(const Vector2<T>& vector) const -> Complex<T>
- Multiply with a vector.
- auto operator/=(T scalar) -> Complex<T>&
- Divide with a scalar and assign.
- auto operator/=(const Vector2<T>& vector) -> Complex<T>&
- Divide with a vector and assign.
- auto operator/(T scalar) const -> Complex<T>
- Divide with a scalar.
- auto operator/(const Vector2<T>& vector) const -> Complex<T>
- Divide with a vector.
- auto operator*(const Complex<T>& other) const -> Complex<T>
- Multiply with a complex number.
- auto dot() const -> T
- Dot product of the complex number.
- auto length() const -> T
- Complex number length.
- auto normalized() const -> Complex<T>
- Normalized complex number (of unit length)
- auto conjugated() const -> Complex<T>
- Conjugated complex number.
- auto inverted() const -> Complex<T>
- Inverted complex number.
- auto invertedNormalized() const -> Complex<T>
- Inverted normalized complex number.
- auto transformVector(const Vector2<T>& vector) const -> Vector2<T>
- Rotate a vector with the complex number.
Function documentation
template<class T>
static Complex<T> Magnum:: Math:: Complex<T>:: fromMatrix(const Matrix2x2<T>& matrix)
Create a complex number from a rotation matrix.
Expects that the matrix is a pure rotation, i.e. orthogonal and without any reflection. See Matrix3::
template<class T>
Magnum:: Math:: Complex<T>:: Complex() constexpr noexcept
Default constructor.
Equivalent to Complex(IdentityInitT).
template<class T>
Magnum:: Math:: Complex<T>:: Complex(IdentityInitT) explicit constexpr noexcept
Identity constructor.
Constructs unit complex number.
template<class T>
Magnum:: Math:: Complex<T>:: Complex(T real,
T imaginary) constexpr noexcept
Construct a complex number from real and imaginary part.
template<class T>
Magnum:: Math:: Complex<T>:: operator Vector2<T>() const explicit constexpr
Convert a complex number to vector.
template<class T>
T* Magnum:: Math:: Complex<T>:: data()
Raw data.
Contrary to what Doxygen shows, returns reference to an one-dimensional fixed-size array of two elements, i.e. T(&)[2]
.
template<class T>
const T* Magnum:: Math:: Complex<T>:: data() const
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
template<class T>
bool Magnum:: Math:: Complex<T>:: isNormalized() const
Whether the complex number is normalized.
Complex number is normalized if it has unit length:
template<class T>
T& Magnum:: Math:: Complex<T>:: real()
Real part ( )
template<class T>
T Magnum:: Math:: Complex<T>:: real() const constexpr
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
template<class T>
T& Magnum:: Math:: Complex<T>:: imaginary()
Imaginary part ( )
template<class T>
T Magnum:: Math:: Complex<T>:: imaginary() const constexpr
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
template<class T>
Complex<T> Magnum:: Math:: Complex<T>:: operator+() const new in Git master
Promotion.
Returns the value as-is.
template<class T>
Complex<T>& Magnum:: Math:: Complex<T>:: operator+=(const Complex<T>& other)
Add a complex number and assign.
The computation is done in-place.
template<class T>
Complex<T>& Magnum:: Math:: Complex<T>:: operator-=(const Complex<T>& other)
Subtract a complex number and assign.
The computation is done in-place.
template<class T>
Complex<T>& Magnum:: Math:: Complex<T>:: operator*=(T scalar)
Multiply with a scalar and assign.
The computation is done in-place.
template<class T>
Complex<T>& Magnum:: Math:: Complex<T>:: operator*=(const Vector2<T>& vector)
Multiply with a vector and assign.
The computation is done in-place.
template<class T>
Complex<T>& Magnum:: Math:: Complex<T>:: operator/=(T scalar)
Divide with a scalar and assign.
The computation is done in-place.
template<class T>
Complex<T>& Magnum:: Math:: Complex<T>:: operator/=(const Vector2<T>& vector)
Divide with a vector and assign.
The computation is done in-place.
template<class T>
T Magnum:: Math:: Complex<T>:: length() const
Complex number length.
See also dot() const which is faster for comparing length with other values.
template<class T>
Complex<T> Magnum:: Math:: Complex<T>:: normalized() const
Normalized complex number (of unit length)
template<class T>
Complex<T> Magnum:: Math:: Complex<T>:: conjugated() const
Conjugated complex number.
template<class T>
Complex<T> Magnum:: Math:: Complex<T>:: inverted() const
Inverted complex number.
See invertedNormalized() which is faster for normalized complex numbers.
template<class T>
Complex<T> Magnum:: Math:: Complex<T>:: invertedNormalized() const
Inverted normalized complex number.
Equivalent to conjugated(). Expects that the complex number is normalized.
template<class T>
Vector2<T> Magnum:: Math:: Complex<T>:: transformVector(const Vector2<T>& vector) const
Rotate a vector with the complex number.
template<class T>
template<class T>
Rad<T> angle(const Complex<T>& normalizedA,
const Complex<T>& normalizedB)
Angle between normalized complex numbers.
Expects that both complex numbers are normalized.
To avoid numerical issues when two complex numbers are very close to each other, the dot product is clamped to the range before being passed to .
template<class T>
template<class T>
Complex<T> operator*(T scalar,
const Complex<T>& complex)
Multiply a scalar with a complex number.
Same as Complex::
template<class T>
template<class T>
Complex<T> lerp(const Complex<T>& normalizedA,
const Complex<T>& normalizedB,
T t)
Linear interpolation of two complex numbers.
Parameters | |
---|---|
normalizedA | First complex number |
normalizedB | Second complex number |
t | Interpolation phase (from range ) |
Expects that both complex numbers are normalized.
template<class T>
template<class T>
Complex<T> slerp(const Complex<T>& normalizedA,
const Complex<T>& normalizedB,
T t)
Spherical linear interpolation of two complex numbers.
Parameters | |
---|---|
normalizedA | First complex number |
normalizedB | Second complex number |
t | Interpolation phase (from range ) |
Expects that both complex numbers are normalized. If the complex numbers are the same, returns the first argument.
template<class T>
template<class T>
Debug& operator<<(Debug& debug,
const Complex<T>& value)
Debug output operator.