Mesh PaterneQuad::remplissageCoin(const int& indicePointCoin, Vector2D& point1Batiment, Vector2D& pointCentre, Vector2D& point3Batiment) { /* point1 X----X point2 | | | | point0 X----X point3 */ Quadrangle centreTmp = *this; // Taille aléatoire float aleatoire = (rand()%100) / 100.0; centreTmp.shrink( _par->minLargeurBatiment + aleatoire*(coeffShrinkMax()-_par->minLargeurBatiment-_par->largeurRuelle) ); // pointCentre = centreTmp[indicePointCoin]; Vector2D shrink = pointCentre - get(indicePointCoin); Vector2D pIpIm1 = get((indicePointCoin-1)%4) - get(indicePointCoin); Vector2D pIpIp1 = get((indicePointCoin+1)%4) - get(indicePointCoin); pIpIm1.normalise(); pIpIp1.normalise(); // disposition des points en losange float dpIpIm1 = shrink.scalareProduct(pIpIm1); dpIpIm1 = shrink.getNorm()*shrink.getNorm() / (dpIpIm1*2); if(dpIpIm1 >= (get((indicePointCoin-1)%4) - get(indicePointCoin)).getNorm()/2) dpIpIm1 = (get((indicePointCoin-1)%4) - get(indicePointCoin)).getNorm()/2 - _par->largeurRuelle/2; float dpIpIp1 = shrink.scalareProduct(pIpIp1); dpIpIp1 = shrink.getNorm()*shrink.getNorm() / (dpIpIp1*2); if(dpIpIp1 >= (get((indicePointCoin+1)%4) - get(indicePointCoin)).getNorm()/2) dpIpIp1 = (get((indicePointCoin+1)%4) - get(indicePointCoin)).getNorm()/2 - _par->largeurRuelle/2; point1Batiment = get(indicePointCoin) + pIpIp1*dpIpIp1; point3Batiment = get(indicePointCoin) + pIpIm1*dpIpIm1; Batiment b = Batiment(Vector3D(get(indicePointCoin).x, get(indicePointCoin).y, 0), Vector3D(point1Batiment.x, point1Batiment.y, 0), Vector3D(pointCentre.x, pointCentre.y, 0), Vector3D(point3Batiment.x, point3Batiment.y, 0), _par); return b.generate(); }
//préfère le mettre dans un fichier de calcul à part. float areaTriangle(const Vector2D& p0, const Vector2D& p1, const Vector2D& p2) { Vector2D ab = p1-p0; Vector2D ac = p2-p0; float base = ab.getNorm(); float d = ab.scalareProduct(ac)/base; float h = sqrt(ac.getNorm2()-d*d); return h*base*0.5; }