Complex.fromPolar constructor

Complex.fromPolar({
  1. required double r,
  2. required double theta,
  3. bool angleInRadians = true,
})

Creates a complex number from the given polar coordinates where r is the radius and theta is the angle.

By default, the angle theta must be expressed in radians but setting angleInRadians = false allows the value to be in degrees.

Implementation

factory Complex.fromPolar({
  required double r,
  required double theta,
  bool angleInRadians = true,
}) {
  final real = r * math.cos(angleInRadians ? theta : _degToRad(theta));
  final imaginary = r * math.sin(angleInRadians ? theta : _degToRad(theta));

  return Complex(real, imaginary);
}