Skip to content

Instantly share code, notes, and snippets.

@sthefanoss
Last active August 31, 2020 16:02
Show Gist options
  • Save sthefanoss/ed5b0eea140b691e39d5916db355d733 to your computer and use it in GitHub Desktop.
Save sthefanoss/ed5b0eea140b691e39d5916db355d733 to your computer and use it in GitHub Desktop.
import "dart:math";
class Complex {
double real;
double imaginary;
Complex(this.real, this.imaginary);
Complex.polar(double magnitude, double angle) {
this.real = magnitude * cos(angle);
this.imaginary = magnitude * sin(angle);
}
factory Complex.polarFactory(double magnitude, double angle) {
var real = magnitude * cos(angle);
var imaginary = magnitude * sin(angle);
return Complex(real, imaginary);
}
String toString() =>
'${real.toStringAsFixed(1)} ${imaginary.toStringAsFixed(1)}';
}
void main() {
Complex a = Complex(-1, 0);
Complex b = Complex.polar(1, pi);
Complex c = Complex.polarFactory(1, pi);
print(a);
print(b);
print(c);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment