/* Structure COMPLEXE Gestion des nombres Complexes Version 1.0 - Last Modif : 21/04/2006 15:52 Développé par SeBeuh < sebeuh [arobase] ajsinfo [point].net > (c) 2006 - http://sebeuh.ajsinfo.net */ using System; using System.Collections.Generic; using System.Text; namespace Complexes { // Structure : Complexe public struct Complexe { // Champs private double _reel; private double _imaginaire; // Constructeur public Complexe(double reel, double imaginaire) { this._reel = reel; this._imaginaire = imaginaire; } // Surcharge de la methode ToString() // renvoi du complexe sous la forme a+ib public override string ToString() { string re = "", img = ""; if(this._reel != 0) re = ((float)this._reel).ToString(); if (this._imaginaire > 0 && this._imaginaire != 1) img = "+" + ((float)this._imaginaire).ToString() + "i"; else if (this._imaginaire == 1) img = "+i"; else if (this._imaginaire < 0 && this._imaginaire != -1) img = ((float)this._imaginaire).ToString() + "i"; else if (this._imaginaire == -1) img = "-i"; return (re + img); } // Surcharge des operateurs // Addition public static Complexe operator +(Complexe c1, Complexe c2) { return (new Complexe((c1.Reel + c2.Reel), (c1.Imaginaire + c2.Imaginaire))); } // Soustraction public static Complexe operator -(Complexe c1, Complexe c2) { return (new Complexe((c1.Reel - c2.Reel), (c1.Imaginaire - c2.Imaginaire))); } // Multiplication public static Complexe operator *(Complexe c1, Complexe c2) { return (new Complexe(((c1.Reel * c2.Reel) - (c1.Imaginaire * c2.Imaginaire)), ((c1.Reel * c2.Imaginaire) + (c2.Reel * c1.Imaginaire)))); } // Division public static Complexe operator /(Complexe c1, Complexe c2) { return (new Complexe(((c1._reel * c2._reel - c1._imaginaire * (-c2._imaginaire)) / (Math.Pow(c2._reel, 2) + Math.Pow(c2._imaginaire, 2))), ( ((c1._reel * (-c2._imaginaire) + c2._reel * c1._imaginaire) / (Math.Pow(c2._reel, 2) + Math.Pow(c2._imaginaire, 2)))))); } // Methodes // Rotation public Complexe Rotation(double angle, Complexe centre) { return (((this - centre) * (new Complexe(Math.Cos(angle), Math.Sin(angle)))) + centre); } // Accesseurs en Get (read only) // Conjugué du complexe public Complexe Conjugue { get { return new Complexe(this._reel, (0 - this._imaginaire)); } } // Module du complexe public double Module { get { return Math.Sqrt((Math.Pow(this._reel, 2) + Math.Pow(this._imaginaire, 2))); } } // Argument du complexe public double Argument { get { return (Math.Atan((this._imaginaire / this._reel))); } } // Carré du complexe public Complexe Carre { get { return new Complexe((Math.Pow(this._reel,2)-Math.Pow(this._imaginaire,2)),(2*this._reel*this._imaginaire)); } } // Accesseurs en Get&Set // Partie Reel public double Reel { get { return this._reel; } set { this._reel = value; } } // Partie Imaginaire public double Imaginaire { get { return this._imaginaire; } set { this._imaginaire = value; } } } }