void Quadrangle::shrink(const float &l)
{

    Vector2D tab[4];

    for(int i=0; i<4; i++){
        Vector2D orth1 = Orthogonal(-((*this)[(i+1)%4]-(*this)[i])).normalise();
        Vector2D orth2 = Orthogonal( ((*this)[(i-1)%4]-(*this)[i])).normalise();

        std::cout << (*this)[i] << " :: " << (*this)[(i+1)%4] << std::endl;
        std::cout << (*this)[(i+1)%4]-(*this)[i] << std::endl;
        std::cout << "orth1 : " << orth1 << std::endl;

        std::cout << (*this)[i] << " :: " << (*this)[(i-1)%4] << std::endl;
        std::cout << ((*this)[(i-1)%4]-(*this)[i]) << std::endl;
        std::cout << "orth2 : " << orth2 << std::endl;
        std::cout << "tab["<<i<<"] : " << tab[i] << std::endl;

        Vector2D v = (orth1 + orth2)/2;

        std::cout << "v.Norm() : " << v.getNorm() << std::endl;
        std::cout << std::endl;

        tab[i] = (*this)[i]+Normalized(v)*(l/(v.getNorm()));
    }

    for(int i=0; i<4; i++){
        std::cout << "tab["<<i<<"] : " << tab[i] << std::endl;
        (*this)[i] = tab[i];
    }
}
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();

}
Example #3
0
//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;
}
Example #4
0
void Polygone::shrinkPoly(int nb, float l)
{
    if(l == 0)
        return;

    Vector2D tab[nb];

    for(int i = 0;	i < nb;	i++)
    {
        Vector2D v1 = Orthogonal(get(i)-get(i+1)).normalised();
        Vector2D v2 = Orthogonal(get(i-1)-get(i)).normalised();

        Vector2D v = (v1+v2)/2;	//quand on augmente de 1 sur v1 ou v2, on augment de v.norm() sur le v.

        tab[i] = get(i)+Normalized(v)*(l/v.getNorm());
    }
    for(int i = 0;	i < nb;	i++)
         set(i, tab[i]);
}