bonhomeExamJanvier/Bonhomme01/PointComplexe.cs

111 lines
3.2 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Numerics;
using System.Drawing;
namespace Bonhomme01
{
class PointComplexe
{
Complex point;
Complex origine;
public int X
{
get { return (int)point.Real; }
}
public int Y
{
get { return (int)point.Imaginary; }
}
public double ABS
{
get
{
DeplacerSurOrigine();
double abs = point.Magnitude;
RetoursPosition();
return abs;
}
set
{
}
}
public PointComplexe(int x, int y, int xo, int yo)
{
point = new Complex(x, y);
origine = new Complex(xo, yo);
}
public PointComplexe(PointComplexe a, PointComplexe b)
{
point = new Complex(b.X, b.Y);
origine = new Complex(a.X, a.Y);
}
public PointComplexe(Point a, Point b)
{
point = new Complex(b.X, b.Y);
origine = new Complex(a.X, a.Y);
}
public PointComplexe(int x, int y, int xo, int yo, double degre)
{
point = new Complex(x, y);
origine = new Complex(xo, yo);
//Console.WriteLine("Avent rotation {0}", point.ToString());
//Console.WriteLine("Avent rotation {0}", point.ToString());
RotateDegre(degre);
//Console.WriteLine("Après rotation {0}", point.ToString());
//Console.WriteLine("Après rotation {0}", point.ToString());
}
public void RotateDegre(double angle)
{
double radian = (angle%360) * (Math.PI / 180);
point = Complex.Subtract(point, origine);
point = Complex.FromPolarCoordinates(point.Magnitude, point.Phase + radian);
point = Complex.Add(point, origine);
}
public void RotateRadian(float radian)
{
point = Complex.Subtract(point, origine);
point = Complex.Add(point, Complex.FromPolarCoordinates(point.Magnitude, point.Phase + radian));
point = Complex.Add(point, origine);
}
public static Point Millieux(PointComplexe a, PointComplexe b)
{
PointComplexe pt = new PointComplexe(a, b);
pt.DeplacerSurOrigine();
pt.point = Complex.FromPolarCoordinates(pt.point.Magnitude / 2, pt.point.Phase);
pt.RetoursPosition();
return new Point(pt.X, pt.Y);
}
public Point Millieux()
{
DeplacerSurOrigine();
point = Complex.FromPolarCoordinates(point.Magnitude / 2, point.Phase);
RetoursPosition();
return new Point(X, Y);
}
public void DeplacerSurOrigine()
{
point = Complex.Subtract(point, origine);
}
public void RetoursPosition()
{
point = Complex.Add(point, origine);
}
public static implicit operator Point(PointComplexe point)
{
return new Point(point.X, point.Y);
}
}
}