1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152
|
void maillage ( Points& maillage,
Triangles& triangles,
int nombre_de_points,
double entree,
double longueur_marche,
double longueur_totale,
double sortie )
{
double aire_totale = longueur_totale*sortie + longueur_marche*(entree-sortie);
int nb_pts_1 = floor(longueur_marche*entree/aire_totale*nombre_de_points);
int nb_pts_2 = floor((longueur_totale-longueur_marche)*entree/aire_totale*nombre_de_points);
int nb_pts_3 = floor((longueur_totale-longueur_marche)*(sortie-entree)/aire_totale*nombre_de_points);
double coef_1 = longueur_marche/entree;
double coef_2 = (longueur_totale-longueur_marche)/entree;
double coef_3 = (longueur_totale-longueur_marche)/(sortie-entree);
int nb_colonnes_2 = floor(sqrt(nb_pts_2*4/3*coef_2));
int nb_colonnes_1 = floor(nb_colonnes_2*longueur_marche/(longueur_totale-longueur_marche));
int nb_colonnes_3 = nb_colonnes_2;
int nb_lignes_2 = floor(sqrt(nb_pts_2*2/coef_2));
while (nb_lignes_2*nb_colonnes_2 < nb_pts_2)
nb_lignes_2++;
int nb_lignes_1 = nb_lignes_2;
int nb_lignes_3 = floor(sqrt(nb_pts_3*2/coef_3));
while (nb_lignes_3*nb_colonnes_3 < nb_pts_3)
nb_lignes_3++;
double delta_x_1 = longueur_marche/(nb_colonnes_1-1);
double delta_y_1 = entree/(nb_lignes_1-1);
double delta_x_2 = (longueur_totale-longueur_marche)/(nb_colonnes_2-1);
double delta_y_2 = delta_y_1;
double delta_x_3 = delta_x_2;
double delta_y_3 = (sortie-entree)/(nb_lignes_3-1);
double x = 0;
double y = 0;
bool gamma = false;
for(int i=0; i<nb_colonnes_1-1; ++i)
{
for(int j=0; j<nb_lignes_1-1; ++j)
{
x = i*delta_x_1;
y = j*delta_y_1;
if (x==0 || y==0 || y==entree) gamma = true;
Point P(x,y,gamma);
x = (i+1)*delta_x_1;
y = j*delta_y_1;
if (x==0 || y==0 || y==entree) gamma = true;
Point Q(x,y,gamma);
x = i*delta_x_1;
y = (j+1)*delta_y_1;
if (x==0 || y==0 || y==entree) gamma = true;
Point R(x,y,gamma);
x = (i+1)*delta_x_1;
y = (j+1)*delta_y_1;
if (x==0 || y==0 || y==entree) gamma = true;
Point S(x,y,gamma);
maillage.ajout(P);
maillage.ajout(Q);
maillage.ajout(R);
Triangle T1( maillage[maillage.nb_points()-1], maillage[maillage.nb_points()-2], maillage[maillage.nb_points()-3] );
triangles.ajout_simple(T1);
maillage.ajout(S);
Triangle T2( maillage[maillage.nb_points()-1], maillage[maillage.nb_points()-2], maillage[maillage.nb_points()-3] );
triangles.ajout_simple(T2);
}
}
for(int i=0; i<nb_colonnes_2-1; ++i)
{
for(int j=0; j<nb_lignes_2-1; ++j)
{
x = i*delta_x_2+longueur_marche;
y = j*delta_y_2;
if (x==longueur_totale || y==entree) gamma = true;
Point P(x,y,gamma);
x = (i+1)*delta_x_2+longueur_marche;
y = j*delta_y_2;
if (x==longueur_totale || y==entree) gamma = true;
Point Q(x,y,gamma);
x = i*delta_x_2+longueur_marche;
y = (j+1)*delta_y_2;
if (x==longueur_totale || y==entree) gamma = true;
Point R (x,y,gamma);
x = (i+1)*delta_x_2+longueur_marche;
y = (j+1)*delta_y_2;
if (x==longueur_totale || y==entree) gamma = true;
Point S (x,y,gamma);
maillage.ajout(P);
maillage.ajout(Q);
maillage.ajout(R);
Triangle T1( maillage[maillage.nb_points()-1], maillage[maillage.nb_points()-2], maillage[maillage.nb_points()-3] );
triangles.ajout_simple(T1);
maillage.ajout(S);
Triangle T2( maillage[maillage.nb_points()-1], maillage[maillage.nb_points()-2], maillage[maillage.nb_points()-3] );
triangles.ajout_simple(T2);
}
}
for(int i=0; i<nb_colonnes_3-1; ++i)
{
for(int j=0; j<nb_lignes_3-1; ++j)
{
x = i*delta_x_3+longueur_marche;
y = j*delta_y_3*(-1);
if (x==longueur_totale || x==longueur_marche || y==-(sortie-entree)) gamma = true;
Point P(x,y,gamma);
x = (i+1)*delta_x_3+longueur_marche;
y = j*delta_y_3*(-1);
if (x==longueur_totale || x==longueur_marche || y==-(sortie-entree)) gamma = true;
Point Q(x,y,gamma);
x = i*delta_x_3+longueur_marche;
y = (j+1)*delta_y_3*(-1);
if (x==longueur_totale || x==longueur_marche || y==-(sortie-entree)) gamma = true;
Point R (x,y,gamma);
x = (i+1)*delta_x_3+longueur_marche;
y = (j+1)*delta_y_3*(-1);
if (x==longueur_totale || x==longueur_marche || y==-(sortie-entree)) gamma = true;
Point S (x,y,gamma);
maillage.ajout(P);
maillage.ajout(Q);
maillage.ajout(R);
Triangle T1( maillage[maillage.nb_points()-1], maillage[maillage.nb_points()-2], maillage[maillage.nb_points()-3] );
triangles.ajout_simple(T1);
maillage.ajout(S);
Triangle T2( maillage[maillage.nb_points()-1], maillage[maillage.nb_points()-2], maillage[maillage.nb_points()-3] );
triangles.ajout_simple(T2);
}
}
cout << "\tnombre de points : " << maillage.nb_points() << endl;
cout << "\tnombre de triangles : " << triangles.nb_triangles() << endl;
//cout << triangles << endl;
} |
Partager