Salut pour le monde , j'ai le code suivant:
la structure vertice:
et la structure triangle:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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 struct vertice { vertice() {id=0; x=0; y=0;}; vertice (double xx, double yy){ x=xx; y=yy;}; vertice(const vertice & ver ){this->id=ver.id; this-> x=ver.x; this-> y=ver.y;}; vertice &operator=(const vertice &ver){ this->id=ver.id; this-> x=ver.x; this->y=ver.y; return *this;}; int id; double x,y; double get_x(){ return x;}; double get_y(){ return y;}; void set_id(int init_val){ id = init_val;}; };
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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 struct triangle { triangle*tv1; triangle*tv3; triangle*tv2; //int h; void set_Center( vertice v) { m_Center=v;}; void set_rayon (double r) {m_R=r;}; vertice * m_Vertices[3]; // the three triangle vertices vertice m_Center; // center of circumcircle double m_R; // radius of circumcircle double m_R2; triangle () { tv1=NULL; tv2=NULL; tv3=NULL; m_Vertices[0]=0; m_Vertices[1]=0; m_Vertices[2]=0; m_R2=0; m_R=0; }; triangle( int x , int y, int z,vector<vertice>& Vertex) :tv1(NULL) ,tv2(NULL) ,tv3(NULL) { *this->m_Vertices[0] = *(&Vertex[x]); *this->m_Vertices[1] = *(&Vertex[y]); *this->m_Vertices[2] = *(&Vertex[z]); }; triangle( vertice & p0, vertice & p1, vertice & p2) :tv1(0) ,tv2(0) ,tv3(0) { m_Vertices[0] = &p0; m_Vertices[1] = &p1; m_Vertices[2] = &p2; }; triangle( vertice * pV) :tv1(0) ,tv2(0) ,tv3(0) { for (int i = 0; i < 3; i++) m_Vertices[i] = pV++; }; triangle( const triangle & tri) : m_Center(tri.m_Center) , m_R(tri.m_R) , m_R2(tri.m_R2) { for (int i = 0; i < 3; i++) { m_Vertices[i] = tri.m_Vertices[i]; } this->tv1= tri.tv1; this->tv2=tri.tv2; this->tv3=tri.tv3; };
et la fonction couper en trois
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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 triangle* coupe( triangle t, vertice *p,vector<vertice>& Vertex) { triangle *t1=NULL; triangle *t2=NULL; triangle *t3=NULL; cout<< "cv"<<endl; cout << " les 3 id de triangle ttmp sont "<<t.m_Vertices[0]->id<< " "<<t.m_Vertices[1]->id<<" " <<t.m_Vertices[2]->id<<endl; //creation des trois nouveau sous-triangle cout << p->id<<" "<<t.m_Vertices[1]->id<<" "<<t.m_Vertices[2]->id<<endl; triangle a (p->id, t.m_Vertices[1]->id, t.m_Vertices[2]->id,Vertex); t1=&a; triangle b(t.m_Vertices[0]->id, p->id, t.m_Vertices[2]->id,Vertex); t2=&b; triangle cc(t.m_Vertices[0]->id, t.m_Vertices[1]->id, p->id,Vertex); t3=&cc; t1->tv2=t2; t1->tv3=t3; t2->tv1=t1; t2->tv3=t3; t3->tv1=t1; t3->tv2=t2; t1->tv1=0; t2->tv2=t.tv2; t3->tv3=t.tv3; cout<< "cv2"<<endl; cout <<" le voisin 2 de la sous-triangle 1 "<< t1->tv2->m_Vertices[0]->id<<" "<< t1->tv2->m_Vertices[1]->id<<" "<< t1->tv2->m_Vertices[2]->id<<endl; return t1; }
la fonction "coupe " sert à decouper le triangle t (en parametre) en trois en inserant le point p (en parametre) puis elle retourne un pointeur sur le premier triangle.
Mon probleme est lors l'appel de la fonction coupe, "les objets" de la structure triangle prend des valeurs quelconques et surtout les 3 voisins ( tv1, tv2,tv3).
je pense que mon probleme dans les constructeurs ( je ne suis pas sur).
s'il vous plaît aidez moi ?
Partager