public static List<MathPoint> ListePointsReseau(Size Dimensions, Double Diametre, TypeReseau_e TypeReseau) { List<MathPoint> pListePoints = new List<MathPoint>(); int pNbH; int pNbV; Double pDimH = Diametre; Double pDimV = Diametre; Double pDecalH; Double pDecalV; switch (TypeReseau) { case TypeReseau_e.Carre: pNbH = (int)Math.Truncate((Dimensions.Width - pDimH) / pDimH); pNbV = (int)Math.Truncate((Dimensions.Height - pDimV) / pDimV); pDecalH = (Dimensions.Width - (pNbH * pDimH)) * 0.5; pDecalV = (Dimensions.Height - (pNbV * pDimV)) * 0.5; for (int y = 0; y <= pNbV; y++) for (int x = 0; x <= pNbH; x++) { MathPoint pPt; pPt.X = pDecalH + (x * pDimH); pPt.Y = pDecalV + (y * pDimV); pListePoints.Add(pPt); } break; case TypeReseau_e.Hexagonal: pDimV = (Diametre / Math.Cos(Math.PI / 6.0)); Double pDistV = pDimV * 3.0 / 4.0; pNbH = (int)Math.Truncate((Dimensions.Width - pDimH) / pDimH); pNbV = (int)Math.Truncate((Dimensions.Height - pDimV) / pDistV); pDecalH = (Dimensions.Width - (pNbH * pDimH)) * 0.5; pDecalV = (Dimensions.Height - (pNbV * pDistV)) * 0.5; for (int y = 0; y <= pNbV; y++) for (int x = 0; x <= pNbH; x++) { MathPoint pPt = new MathPoint(); if ((y % 2) == 0) { pPt.X = pDecalH + (x * pDimH); pPt.Y = pDecalV + (y * pDistV); pListePoints.Add(pPt); } else if (x < pNbH) { pPt.X = pDecalH + 0.5 * Diametre + (x * pDimH); pPt.Y = pDecalV + (y * pDistV); pListePoints.Add(pPt); } } break; } return pListePoints; }
public static List<MathVecteur> ListVecteursMatrice(Double Diametre, Double Pas, TypeReseau_e TypeReseau) { List<MathPoint> pListePoints = new List<MathPoint>(); int pNbH; int pNbV; Double pDimH = Diametre; Double pDimV = Diametre; Double pDecalH; Double pDecalV; pNbH = (int)Math.Truncate(pDimH / Pas); pNbV = (int)Math.Truncate(pDimV / Pas); pDecalH = (pDimH - (pNbH * Pas)) * 0.5; pDecalV = (pDimV - (pNbV * Pas)) * 0.5; MathPoint PtCentre = new MathPoint(pDimH * 0.5, pDimV * 0.5); switch (TypeReseau) { case TypeReseau_e.Carre: for (int y = 0; y <= pNbV; y++) for (int x = 0; x <= pNbH; x++) { MathPoint pPt; pPt.X = pDecalH + (x * Pas); pPt.Y = pDecalV + (y * Pas); pListePoints.Add(pPt); } break; case TypeReseau_e.Hexagonal: Double pCoteV = (pDimV / Math.Cos(Math.PI / 6.0)); MathPoint Pt1 = new MathPoint(0.0, pCoteV / 4.0); MathPoint Pt2 = new MathPoint(pDimH * 0.5, 0.0); MathPoint Pt3 = new MathPoint(pDimH, pCoteV / 4.0); MathPoint Pt4 = new MathPoint(pDimH, pCoteV * 3.0 / 4.0); MathPoint Pt5 = new MathPoint(pDimH * 0.5, pCoteV); MathPoint Pt6 = new MathPoint(0.0, pCoteV * 3.0 / 4.0); PtCentre.Y = pCoteV * 0.5; for (int y = 0; y <= pNbV; y++) for (int x = 0; x <= pNbH; x++) { MathPoint pPt; pPt.X = pDecalH + (x * Pas); pPt.Y = pDecalV + (y * Pas); Boolean T = true; MathPoint PtTest = pPt; T = T & SensHoraire(Pt1, Pt2, PtTest); T = T & SensHoraire(Pt2, Pt3, PtTest); T = T & SensHoraire(Pt4, Pt5, PtTest); T = T & SensHoraire(Pt5, Pt6, PtTest); if (T) pListePoints.Add(pPt); } break; } List<MathVecteur> pListeVecteurs = new List<MathVecteur>(); foreach (MathPoint Pt in pListePoints) { MathVecteur pV = new MathVecteur(PtCentre, Pt); pListeVecteurs.Add(pV); } return pListeVecteurs; }
public List<Poincon> ListePoincons(List<Plage> ListePlages, Double Jeu, Size DimFinale, TypeReseau_e TypeReseau) { List<Poincon> pListePoincons = new List<Poincon>(); /// On cherche le diametre max Double DiamMax = 0; foreach (Plage P in ListePlages) { if (P.Intitule > DiamMax) DiamMax = P.Intitule; } /// On rajoute le jeu pour avoir l'entraxe du réseau DiamMax += Jeu; /// On calcul les facteurs de conversion Double MmParPx = (Double)DimFinale.Width / (Double)_Image.Size.Width; Double PxParMm = 1.0 / MmParPx; /// On récupère la liste des points du réseau /// On récupère la liste des point de l'empreinte : carré ou héxagonale List<MathPoint> pListePointsReseau = Reseau.ListePointsReseau(DimFinale, DiamMax, TypeReseau); List<MathVecteur> pListePointsMatrice = Reseau.ListVecteursMatrice(DiamMax, MmParPx, TypeReseau); Verrouiller(); foreach (MathPoint Pt in pListePointsReseau) { float Val = 0; foreach (MathVecteur V in pListePointsMatrice) { MathPoint PtTmp = Pt; PtTmp.Deplacer(V); int x = (int)Math.Truncate(PtTmp.X * PxParMm); if (x >= Width) x = Width - 1; int y = (int)Math.Truncate(PtTmp.Y * PxParMm); if (y >= Height) y = Height - 1; Color C = GetPixel(x, y); Val += C.GetBrightness() * _PlageCouleur; } Val /= pListePointsMatrice.Count; Poincon pPc = new Poincon(); pPc.Point = Pt; foreach (Plage Pc in ListePlages) { if ((Val >= Pc.Min) && (Val <= Pc.Max)) { pPc.Diametre = Pc.Intitule; pListePoincons.Add(pPc); break; } } } Liberer(); return pListePoincons; }