Last active
August 31, 2020 16:02
-
-
Save sthefanoss/ed5b0eea140b691e39d5916db355d733 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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