Complex Manual
maxon::Complex is a MAXON API class used to represent complex numbers and deliver standard mathematical operations. A complex number is a number that can be expressed in the form a + bi ,其中 a and b are real numbers, and i is a solution of the equation x^2 = -1 , which is called an imaginary number because there is no real number that satisfies this equation. For the complex number a + bi , a is called the real part, and b is called the imaginary part. Usually complex numbers are represented in a 2D plane known as "complex plane" or "Argand plane" with the abscissa representing the real part and the ordinate representing the imaginary part.
A maxon::Complex instance can be created on the stack and initialized through the proper method using a numerical data type as template:
// just allocate an zero-valued complex object const maxon::Complex<maxon::Float> zeroComplex;
// just allocate a complex object defining the real part const maxon::Complex<maxon::Float> realOnlyComplex(1.4);
// just allocate a complex object defining both real and imaginary part const maxon::Complex<maxon::Float> fullComplex(1.4, 4);
The maxon::Complex class delivers a set of standard mathematical operators to perform calculation with complex numbers. The operators delivered are:
// just allocate a complex object defining the real part const maxon::Complex<maxon::Float> complexA(2);
// just allocate a complex object defining both real and imaginery part maxon::Complex<maxon::Float> complexB(1, -3);
// sum A to B complexB += complexA;
// allocate a new complex number and assign the difference between B and A const maxon::Complex<maxon::Float> complexC = complexB - complexA;
// allocate a new complex number and assign the product between A and C const maxon::Complex<maxon::Float> complexD = complexA * complexC;
// scale the complexB by a given amount complexB = complexB * 10;
The maxon::Complex class is provided with a number of get methods to retrieve useful data from a maxon::Complex instance:
// just allocate a complex object defining the real part const maxon::Complex<maxon::Float> complexA(2, 2);
// get the length of the vector representing the complex number on the Argand plane const maxon::Float lengthValue = complexA.GetLength();
// get the angle (in radians) of the vector representing the complex number on the Argand plane const maxon::Float angleValue = complexA.GetPhase();
// get the squared length of the vector representing the complex number on the Argand plane const maxon::Float squaredlengthValue = complexA.GetSquaredLength();
// get the normalized vector representing the complex number on the Argand plane const maxon::Complex<maxon::Float> normalized = complexA. GetNormalized ();
// get the complex conjugate of the vector representing the complex number on the Argand plane const maxon::Complex<maxon::Float> conjugate = complexA. GetConjugate ();
// get the sqrt of the complex number const maxon::Complex<maxon::Float> sqrt = complexA. GetSqrt ();
// get the natural log of the complex number const maxon::Complex<maxon::Float> log = complexA. GetLog () iferr_return ;
// get the division of the complex number by the passed value // NOTE: the result is stored in the calling instance const maxon::Complex<maxon::Float> divisor(2, 4); maxon::Complex<maxon::Float> complexB(6, 8); complexB.GetDivision(divisor) iferr_return ;
The maxon::Complex class is provided with a number of "set" methods to define a maxon::Complex instance:
// just allocate a few zero-valued complex objects maxon::Complex<maxon::Float> complexA; maxon::Complex<maxon::Float> complexB; maxon::Complex<maxon::Float> complexC;
// set the length of the vector representing the complex number on the Argand plane complexA. SetLength (3);
// set the angle of the vector representing the complex number on the Argand plane complexA. SetPhase (- PI05 );
// set the length and angle of the vector representing the complex number on the Argand plane complexB. SetPolar (3, PI05 );
// set a complex number according to e^(i*x) where x is the passed value complexC. SetExp (5);
A maxon::Complex instance can be converted to maxon::String using:
// just allocate a complex object const maxon::Complex<maxon::Float> complexA(1.45, -0.4); const maxon::String stringComplex = complexA. ToString ( nullptr ); DiagnosticOutput (diagIDString + "complexA: @" , complexA); DiagnosticOutput (diagIDString + "complexA.ToString(): @" , stringComplex);
A maxon::Complex instance can be read from and written to disk by serializing the data contained using the conventional functions.
// This example shows how to store and retrieve a maxon::Complex from a file. const maxon::Complex<maxon::Float> savedComplex(-1, 3);// file URL const maxon::Url url = (targetFolder + "complex.txt" _s) iferr_return ; const maxon::Id fileID( "net.maxonexample.complex" );
// save to file maxon::WriteDocument (url, maxon::OPENSTREAMFLAGS::NONE , fileID, savedComplex, maxon::IOFORMAT::JSON ) iferr_return ;
// read from file maxon::Complex<maxon::Float> loadedComplex; maxon::ReadDocument (url, fileID, loadedComplex) iferr_return ;