2018-01-03 13:18:01 +01:00
|
|
|
|
/*
|
|
|
|
|
* Base des objets Bras et jambe
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
2018-01-05 01:51:12 +01:00
|
|
|
|
using System.Drawing;
|
2018-01-03 13:18:01 +01:00
|
|
|
|
using System.Linq;
|
2018-01-05 01:51:12 +01:00
|
|
|
|
using System.Numerics;
|
2018-01-03 13:18:01 +01:00
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
2018-01-04 14:03:06 +01:00
|
|
|
|
using System.Windows.Forms;
|
2018-01-03 13:18:01 +01:00
|
|
|
|
|
|
|
|
|
namespace Bonhomme02
|
|
|
|
|
{
|
|
|
|
|
class BaseBJ
|
|
|
|
|
{
|
2018-01-05 01:51:12 +01:00
|
|
|
|
enum Articulation { Epaule, Coude, Poignet, Bassin = Epaule, Genou = Coude, Cheville = Poignet };
|
|
|
|
|
public Peau Haut, Millieux, Bas, parent;
|
|
|
|
|
double longueur;
|
2018-01-04 11:34:30 +01:00
|
|
|
|
public BaseBJ()
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
2018-01-05 12:19:46 +01:00
|
|
|
|
public BaseBJ(PictureBox Hebergeur, ref Peau parent, Peau bas, double longueur, double epaisseur, double angle) : this( Hebergeur, ref parent, longueur, epaisseur, angle)
|
2018-01-04 11:34:30 +01:00
|
|
|
|
{
|
2018-01-04 14:03:06 +01:00
|
|
|
|
this.Bas = bas;
|
|
|
|
|
this.Bas.parent = this.Millieux;
|
2018-01-05 12:19:46 +01:00
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
public BaseBJ(PictureBox Hebergeur, ref Peau parent, double longueur, double epaisseur, double angle)
|
|
|
|
|
{
|
|
|
|
|
this.parent = parent;
|
|
|
|
|
this.longueur = longueur;
|
|
|
|
|
this.Haut = new Peau(Hebergeur, ref parent, longueur / 2, epaisseur, angle);
|
|
|
|
|
this.Millieux = new Peau(Hebergeur, ref this.Haut, longueur / 2, epaisseur, angle);
|
|
|
|
|
|
2018-01-04 14:03:06 +01:00
|
|
|
|
}
|
2018-01-05 15:29:45 +01:00
|
|
|
|
public BaseBJ(PictureBox Hebergeur, double longueur, double epaisseur, double angle)
|
|
|
|
|
{
|
|
|
|
|
this.longueur = longueur;
|
|
|
|
|
this.Haut = new Peau(Hebergeur, ref parent, longueur / 2, epaisseur, angle);
|
|
|
|
|
this.Millieux = new Peau(Hebergeur, ref this.Haut, longueur / 2, epaisseur, angle);
|
|
|
|
|
}
|
2018-01-04 14:03:06 +01:00
|
|
|
|
public void Afficher(IntPtr handle)
|
|
|
|
|
{
|
|
|
|
|
Haut.Afficher(handle);
|
|
|
|
|
Millieux.Afficher(handle);
|
|
|
|
|
Bas.Afficher(handle);
|
2018-01-04 11:34:30 +01:00
|
|
|
|
}
|
2018-01-05 01:51:12 +01:00
|
|
|
|
public void Cacher(IntPtr handle)
|
|
|
|
|
{
|
|
|
|
|
Haut.Cacher(handle);
|
|
|
|
|
Millieux.Cacher(handle);
|
|
|
|
|
Bas.Cacher(handle);
|
|
|
|
|
}
|
|
|
|
|
public double TrouverAngleHaut(Point pt)
|
|
|
|
|
{
|
|
|
|
|
Point ptOrigine = parent.Coordonnee + parent.longueur;
|
|
|
|
|
Complex vecteur = new Complex(pt.X- ptOrigine.X, pt.Y- ptOrigine.Y);
|
|
|
|
|
return vecteur.Phase;
|
|
|
|
|
}
|
|
|
|
|
public double TrouverAngleMillieux(Point pt)
|
|
|
|
|
{
|
|
|
|
|
Point ptOrigine = Millieux.Coordonnee;
|
|
|
|
|
Complex vecteur = new Complex(pt.X - ptOrigine.X, pt.Y - ptOrigine.Y);
|
|
|
|
|
return vecteur.Phase;
|
|
|
|
|
}
|
|
|
|
|
public Point TouverPointMillieux(Point bas)
|
|
|
|
|
{
|
2018-01-05 12:19:46 +01:00
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
Point H = Haut.Coordonnee;
|
|
|
|
|
//Point M = new Point() ; //Inconnue
|
|
|
|
|
Point B = new Point(bas.X - H.X, bas.Y - H.Y); //On part du principe que H est 0;0
|
2018-01-05 01:51:12 +01:00
|
|
|
|
|
2018-01-05 12:19:46 +01:00
|
|
|
|
Complex tt = new Complex(B.X, B.Y);
|
2018-01-05 01:51:12 +01:00
|
|
|
|
|
2018-01-05 12:19:46 +01:00
|
|
|
|
double a = Math.Sqrt(4 * Math.Pow(Haut.longueur.ABS, 2) - Math.Pow(B.X, 2) - Math.Pow(B.Y, 2));
|
|
|
|
|
double b = Math.Sqrt(Math.Pow(B.X, 2) + Math.Pow(B.Y, 2));
|
2018-01-05 01:51:12 +01:00
|
|
|
|
|
2018-01-05 12:19:46 +01:00
|
|
|
|
double cooMX = (B.Y * a + B.X * b);
|
|
|
|
|
cooMX /= 2 * b;
|
|
|
|
|
double cooMY = -(B.X * a - B.Y * b);
|
|
|
|
|
cooMY /= 2 * b;
|
2018-01-05 01:51:12 +01:00
|
|
|
|
|
2018-01-05 12:19:46 +01:00
|
|
|
|
Complex t = new Complex(cooMX, cooMY);
|
|
|
|
|
cooMX += H.X;
|
|
|
|
|
cooMY += H.Y;
|
|
|
|
|
int xx = (int)Math.Round(cooMX);
|
|
|
|
|
int yy = (int)Math.Round(cooMY);
|
|
|
|
|
return new Point(xx, yy);
|
|
|
|
|
}
|
|
|
|
|
catch(Exception e)
|
|
|
|
|
{
|
|
|
|
|
Console.WriteLine("Erreur Point millieux : " + e);
|
|
|
|
|
return new Point(0, 0);
|
|
|
|
|
}
|
2018-01-05 01:51:12 +01:00
|
|
|
|
}
|
|
|
|
|
public void Bouger(int X, int Y)
|
|
|
|
|
{
|
|
|
|
|
Point nouveauPtBas = new Point(Bas.X + X, Bas.Y + Y);
|
|
|
|
|
Point nouveauPtMillieux = TouverPointMillieux(nouveauPtBas);
|
2018-01-05 12:19:46 +01:00
|
|
|
|
if(nouveauPtMillieux.X != 0 || nouveauPtMillieux.Y != 0)
|
2018-01-05 01:51:12 +01:00
|
|
|
|
{
|
|
|
|
|
Haut.Angle = TrouverAngleHaut(nouveauPtMillieux);
|
|
|
|
|
Millieux.Angle = TrouverAngleMillieux(nouveauPtBas);
|
2018-01-05 12:19:46 +01:00
|
|
|
|
}
|
2018-01-05 01:51:12 +01:00
|
|
|
|
}
|
|
|
|
|
|
2018-01-03 13:18:01 +01:00
|
|
|
|
}
|
|
|
|
|
}
|