Complex analysis
๐งฉ Complex Numbersโ
var a = new ComplexNumber(3, 2);
var b = new ComplexNumber(5, 3);
var sum = a + b;
var product = a * b;
var power = a.Pow(2); // 5 + 12i
Exponential form (Euler's formula) โ
new ComplexNumber(0, Math.PI).Exponential(); // -1
๐ Complex Functionsโ
A ComplexFunction represents a mapping decomposed into its real and imaginary parts:
namespace Numerics.Objects
Constructing a ComplexFunction
From real/imaginary component functions:
var f = new ComplexFunction(
re: point => point.x * point.x - point.y * point.y, // u(x,y) = xยฒ - yยฒ
im: point => 2 * point.x * point.y // v(x,y) = 2xy
);
From a complex-valued function :
var f = new ComplexFunction(z => z.Pow(2)); // f(z) = zยฒ
๐จ Jacobianโ
The Jacobian matrix of a complex function :
var f = new ComplexFunction(z => z.Pow(2));
Matrix jacobian = f.Jacobian((1, 2));
๐ Analyticity (CauchyโRiemann equations)โ
A complex function is analytic (holomorphic) at a point if and only if the CauchyโRiemann equations hold:
var f = new ComplexFunction(z => z.Pow(2));
bool analytic = f.IsAnalytical((1, 2)); // true โ zยฒ is entire
var g = new ComplexFunction(
re: point => point.x * point.x + point.y * point.y, // |z|ยฒ
im: point => 0
);
bool notAnalytic = g.IsAnalytical((1, 1)); // false โ |z|ยฒ is not analytic
๐ Quaternionโ
Quaternions generalize complex numbers to 4 dimensions: . They are the standard representation for 3D rotations โ compact (4 doubles vs 9 for a matrix), numerically stable, and free of gimbal lock.
Algebraic hierarchy:
// Create from axis + angle
var q = Quaternion.FromAxisAngle(new Vector(0, 0, 1), Math.PI / 2); // 90ยฐ about Z
// Rotate a vector: v' = qยทvยทq*
var rotated = q.Rotate(new Vector(1, 0, 0)); // โ (0, 1, 0)
// Compose rotations via multiplication (non-commutative)
var q2 = Quaternion.FromAxisAngle(new Vector(0, 1, 0), Math.PI / 3);
var combined = q2 * q; // q first, then q2
// Convert to/from 3ร3 rotation matrix
Matrix m = q.ToMatrix();
Quaternion recovered = Quaternion.FromMatrix(m);
// Euler angles (ZYX convention)
var q3 = Quaternion.FromEulerAngles(roll: 0.3, pitch: 0.5, yaw: 0.7);
var (roll, pitch, yaw) = q3.ToEulerAngles();
// Axis-angle round-trip
var (axis, angle) = q.ToAxisAngle();
Interpolation:
// Spherical linear interpolation (constant angular velocity)
var halfway = Quaternion.Slerp(qStart, qEnd, 0.5);
// Normalized linear interpolation (cheaper, good for small angles)
var approx = Quaternion.Lerp(qStart, qEnd, 0.5);
Integration (for physics simulation):
// Integrate orientation with angular velocity ฯ over time step dt
var q = Quaternion.Identity;
var omega = new Vector(0, 0, 1); // 1 rad/s about Z
q = Quaternion.IntegrateOrientation(q, omega, dt: 0.001);
Bridge from ComplexNumber:
// Embed โ into โ โ preserves complex multiplication
var c = new ComplexNumber(3, 2);
var q = Quaternion.FromComplexNumber(c); // (3, 2, 0, 0)