template<class T>
Magnum::Math::Complex class

Complex number.

Template parameters
T Data type

Represents 2D rotation. See 2D and 3D transformations for brief introduction.

Public types

using Type = T
Underlying data type.

Public static functions

static auto rotation(Rad<T> angle) -> Complex<T>
Rotation complex number.
static auto fromMatrix(const Matrix2x2<T>& matrix) -> Complex<T>
Create complex number from rotation matrix.

Constructors, destructors, conversion operators

Complex(IdentityInitT = IdentityInit) constexpr noexcept
Default constructor.
Complex(ZeroInitT) explicit constexpr noexcept
Construct zero-initialized complex number.
Complex(NoInitT) explicit noexcept
Construct without initializing the contents.
Complex(T real, T imaginary) constexpr noexcept
Construct complex number from real and imaginary part.
Complex(const Vector2<T>& vector) explicit constexpr noexcept
Construct complex number from vector.
template<class U>
Complex(const Complex<U>& other) explicit constexpr noexcept
Construct complex number from another of different type.
template<class U, class V = decltype(Implementation::ComplexConverter<T, U>::from(std::declval<U>()))>
Complex(const U& other) explicit constexpr
Construct complex number from external representation.
Complex(const Complex<T>&) noexcept defaulted constexpr
Copy constructor.
template<class U, class V = decltype(Implementation::ComplexConverter<T, U>::to(std::declval<Complex<T>>()))>
operator U() const explicit constexpr
Convert complex number to external representation.
operator Vector2<T>() const explicit constexpr
Convert complex number to vector.

Public functions

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() const -> T constexpr
Real part.
auto imaginary() const -> T constexpr
Imaginary part.
auto angle() const -> Rad<T>
Rotation angle of complex number.
auto toMatrix() const -> Matrix2x2<T>
Convert complex number to rotation matrix.
auto operator+=(const Complex<T>& other) -> Complex<T>&
Add complex number and assign.
auto operator+(const Complex<T>& other) const -> Complex<T>
Add complex number.
auto operator-() const -> Complex<T>
Negated complex number.
auto operator-=(const Complex<T>& other) -> Complex<T>&
Subtract complex number and assign.
auto operator-(const Complex<T>& other) const -> Complex<T>
Subtract complex number.
auto operator*=(T scalar) -> Complex<T>&
Multiply with scalar and assign.
auto operator*(T scalar) const -> Complex<T>
Multiply with scalar.
auto operator/=(T scalar) -> Complex<T>&
Divide with scalar and assign.
auto operator/(T scalar) const -> Complex<T>
Divide with scalar.
auto operator*(const Complex<T>& other) const -> Complex<T>
Multiply with 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 vector with complex number.

Function documentation

template<class T>
static Complex<T> Magnum::Math::Complex<T>::rotation(Rad<T> angle)

Rotation complex number.

Parameters
angle Rotation angle (counterclockwise)
\[ c = cos \theta + i sin \theta \]

template<class T>
static Complex<T> Magnum::Math::Complex<T>::fromMatrix(const Matrix2x2<T>& matrix)

Create complex number from rotation matrix.

Expects that the matrix is orthogonal (i.e. pure rotation).

template<class T>
Magnum::Math::Complex<T>::Complex(IdentityInitT = IdentityInit) constexpr noexcept

Default constructor.

Constructs unit complex number.

\[ c = 1 + i0 \]

template<class T>
Magnum::Math::Complex<T>::Complex(T real, T imaginary) constexpr noexcept

Construct complex number from real and imaginary part.

\[ c = a + ib \]

template<class T>
Magnum::Math::Complex<T>::Complex(const Vector2<T>& vector) explicit constexpr noexcept

Construct complex number from vector.

To be used in transformations later.

\[ c = v_x + iv_y \]

template<class T> template<class U>
Magnum::Math::Complex<T>::Complex(const Complex<U>& other) explicit constexpr noexcept

Construct complex number from another of different type.

Performs only default casting on the values, no rounding or anything else.

template<class T>
Magnum::Math::Complex<T>::operator Vector2<T>() const explicit constexpr

Convert complex number to vector.

\[ \boldsymbol v = \begin{pmatrix} a \\ b \end{pmatrix} \]

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:

\[ |c \cdot c - 1| < 2 \epsilon + \epsilon^2 \cong 2 \epsilon \]

template<class T>
Rad<T> Magnum::Math::Complex<T>::angle() const

Rotation angle of complex number.

\[ \theta = atan2(b, a) \]

template<class T>
Matrix2x2<T> Magnum::Math::Complex<T>::toMatrix() const

Convert complex number to rotation matrix.

\[ M = \begin{pmatrix} a & -b \\ b & a \end{pmatrix} \]

template<class T>
Complex<T>& Magnum::Math::Complex<T>::operator+=(const Complex<T>& other)

Add complex number and assign.

The computation is done in-place.

\[ c_0 + c_1 = (a_0 + a_1) + i(b_0 + b_1) \]

template<class T>
Complex<T> Magnum::Math::Complex<T>::operator+(const Complex<T>& other) const

Add complex number.

template<class T>
Complex<T> Magnum::Math::Complex<T>::operator-() const

Negated complex number.

\[ -c = -a -ib \]

template<class T>
Complex<T>& Magnum::Math::Complex<T>::operator-=(const Complex<T>& other)

Subtract complex number and assign.

The computation is done in-place.

\[ c_0 - c_1 = (a_0 - a_1) + i(b_0 - b_1) \]

template<class T>
Complex<T> Magnum::Math::Complex<T>::operator-(const Complex<T>& other) const

Subtract complex number.

template<class T>
Complex<T>& Magnum::Math::Complex<T>::operator*=(T scalar)

Multiply with scalar and assign.

The computation is done in-place.

\[ c \cdot t = ta + itb \]

template<class T>
Complex<T> Magnum::Math::Complex<T>::operator*(T scalar) const

Multiply with scalar.

template<class T>
Complex<T>& Magnum::Math::Complex<T>::operator/=(T scalar)

Divide with scalar and assign.

The computation is done in-place.

\[ \frac c t = \frac a t + i \frac b t \]

template<class T>
Complex<T> Magnum::Math::Complex<T>::operator/(T scalar) const

Divide with scalar.

template<class T>
Complex<T> Magnum::Math::Complex<T>::operator*(const Complex<T>& other) const

Multiply with complex number.

\[ c_0 c_1 = (a_0 + ib_0)(a_1 + ib_1) = (a_0 a_1 - b_0 b_1) + i(a_1 b_0 + a_0 b_1) \]

template<class T>
T Magnum::Math::Complex<T>::dot() const

Dot product of the complex number.

Should be used instead of length() for comparing complex number length with other values, because it doesn't compute the square root.

\[ c \cdot c = a^2 + b^2 \]

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.

\[ |c| = \sqrt{c \cdot c} \]

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.

\[ c^* = a - ib \]

template<class T>
Complex<T> Magnum::Math::Complex<T>::inverted() const

Inverted complex number.

See invertedNormalized() which is faster for normalized complex numbers.

\[ c^{-1} = \frac{c^*}{|c|^2} = \frac{c^*}{c \cdot c} \]

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.

\[ c^{-1} = \frac{c^*}{c \cdot c} = c^* \]

template<class T>
Vector2<T> Magnum::Math::Complex<T>::transformVector(const Vector2<T>& vector) const

Rotate vector with complex number.

\[ v' = c v = c (v_x + iv_y) \]

template<class T> template<class T>
T dot(const Complex<T>& a, const Complex<T>& b)

Dot product of two complex numbers.

\[ c_0 \cdot c_1 = a_0 a_1 + b_0 b_1 \]

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.

\[ \theta = acos \left( \frac{Re(c_0 \cdot c_1))}{|c_0| |c_1|} \right) = acos (a_0 a_1 + b_0 b_1) \]

template<class T> template<class T>
Complex<T> operator*(T scalar, const Complex<T>& complex)

Multiply scalar with complex.

Same as Complex::operator*(T) const.

template<class T> template<class T>
Complex<T> operator/(T scalar, const Complex<T>& complex)

Divide complex with number and invert.

\[ \frac t c = \frac t a + i \frac t b \]

template<class T> template<class T>
Corrade::Utility::Debug& operator<<(Corrade::Utility::Debug& debug, const Complex<T>& value)

Debug output operator.