/* Classe COMPLEXE Gestion des nombres Complexes Version 1.1 - Last Modif : 22/02/2007 15:52 Développé par SeBeuH < sebeuh [arobase] ajsinfo [point].net > (c) 2006-2007 - http://sebeuh.ajsinfo.net */ using System; using System.Collections.Generic; using System.Text; using System.Drawing; namespace Complexes { public class Complexe { #region Champs privés private double _reel; private double _imaginaire; #endregion #region Constructeurs public Complexe() : this(0, 0) { } public Complexe(Point point) : this(point.X, point.Y) { } public Complexe(double reel, double imaginaire) { this._reel = reel; this._imaginaire = imaginaire; } #endregion #region ToString // Renvoi du complexe sous la forme a+ib public override string ToString() { StringBuilder cmpStr = new StringBuilder(); if(this._reel != 0) cmpStr.Append((float)this._reel); if (this._imaginaire > 0 && this._imaginaire != 1) cmpStr.Append(String.Format("+{0}i", ((float)this._imaginaire).ToString())); else if (this._imaginaire == 1) cmpStr.Append("+i"); else if (this._imaginaire < 0 && this._imaginaire != -1) cmpStr.Append(String.Format("{0}i", ((float)this._imaginaire).ToString())); else if (this._imaginaire == -1) cmpStr.Append("-i"); return cmpStr.ToString(); } #endregion #region 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)))))); } #endregion #region Methodes // Rotation public Complexe Rotation(double angle, Complexe centre) { return (((this - centre) * (new Complexe(Math.Cos(angle), Math.Sin(angle)))) + centre); } #endregion #region 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)); } } #endregion #region 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; } } // Point public Point Point { get { return new Point((int)this._reel, (int)this._imaginaire); } set { this._reel = value.X; this._imaginaire = value.Y; } } #endregion } }