Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace Fractals
- {
- public struct Complex
- {
- public double Real;
- public double Imag;
- public double Magnitude
- {
- get { return Math.Sqrt(Real * Real + Imag * Imag); }
- set
- {
- var phase = Phase;
- Real = value * Math.Cos(phase);
- Imag = value * Math.Sin(phase);
- }
- }
- public double Phase
- {
- get { return Math.Atan2(Imag, Real); }
- set
- {
- var mag = Magnitude;
- Real = mag * Math.Cos(value);
- Imag = mag * Math.Sin(value);
- }
- }
- public Complex(double real, double imag)
- {
- Real = real;
- Imag = imag;
- }
- public static Complex operator +(Complex left, Complex right)
- {
- var result = new Complex(left.Real, left.Imag);
- result.Real += right.Real;
- result.Imag += right.Imag;
- return result;
- }
- public static Complex operator -(Complex left, Complex right)
- {
- var result = new Complex(left.Real, left.Imag);
- result.Real -= right.Real;
- result.Imag -= right.Imag;
- return result;
- }
- public static Complex operator *(Complex left, Complex right)
- {
- var result = new Complex(left.Real, left.Imag);
- result.Magnitude *= right.Magnitude;
- result.Phase += right.Phase;
- return result;
- }
- public static Complex operator /(Complex left, Complex right)
- {
- var result = new Complex(left.Real, left.Imag);
- result.Magnitude /= right.Magnitude;
- result.Phase -= right.Phase;
- return result;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement