/
obj0_Vertex.pde
147 lines (125 loc) · 4.09 KB
/
obj0_Vertex.pde
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
class Vertex {
Vec3D v;
int id;
int[] cids; //connection ids
int[] cids_e; //connection ids edge id
Vec3D targetDir; //the rainflow direction to test
int tID; //rainflow target id
float tA; //rainflow target angle
int tID_e; //rainflow target id edge
boolean blIsSeed= false;
boolean lock= false;
//dijkstra:
float fdist=999999; //final distance
int pid= 999999; //previous node id
boolean blsettle= false;
Vertex(Vec3D _v, int _id) {
v= _v;
id= _id;
targetDir= new Vec3D (1, 0, 0);
}
Vertex() {
}
//Creation==============================================================================
//======================================================================================
//Initiation============================================================================
//======================================================================================
void initiate() {
initiateConnection();
getTargetVertex(targetDir); //the connection id if rainflow direction
}
void initiateConnection() {
//collect all edge connections
String st= "";
String st_e= "";
for (int i=0; i<allEdges.size(); i++) {
Edge e= (Edge) allEdges.get(i);
if (id==e.a.id) {
st= st + e.b.id + ";";
st_e= st_e + e.id + ";";
} else if (id==e.b.id) {
st= st + e.a.id + ";";
st_e= st_e + e.id + ";";
}
}
//store in a index list
int[] cidsT= int(split(st, ';'));
cids= new int[cidsT.length-1];
int[] cids_eT= int(split(st_e, ';'));
cids_e= new int[cids_eT.length-1];
for (int i=0; i<cidsT.length-1; i++) {
cids[i]= cidsT[i];
cids_e[i]= cids_eT[i];
}
}
int getTargetVertexID(Vec3D tDir) { //target direction
float angleMin=999999;
int idMin=0;
for (int i=0; i< cids.length; i++) {
Vertex vn= (Vertex) allVertices.get(cids[i]); //neighbour vertex
Vec3D vnDir= vn.v.sub(v); //neighbour vertex direction
float angle= tDir.angleBetween(vnDir, true);
if (angle < angleMin) {
angleMin= angle;
idMin= cids[i];
}
}
return idMin;
}
void getTargetVertex(Vec3D tDir) { //target direction
float angleMin=999999;
int idMin=0;
int idMin_e= 0;
for (int i=0; i< cids.length; i++) {
Vertex vn= (Vertex) allVertices.get(cids[i]); //neighbour vertex
Vec3D vnDir= vn.v.sub(v); //neighbour vertex direction
float angle= tDir.angleBetween(vnDir, true);
if (angle < angleMin) {
angleMin= angle;
idMin= cids[i];
idMin_e= cids_e[i];
}
}
tA= angleMin;
tID= idMin;
tID_e= idMin_e;
}
//Setup=================================================================================
//======================================================================================
//Update================================================================================
//======================================================================================
//Draw==================================================================================
//======================================================================================
void display() {
stroke(255, 0, 0);
strokeWeight(4);
point(v.x, v.y, v.z);
if (pid != 999999) {
stroke(255, 366, 0);
strokeWeight(4);
Vertex vpre= (Vertex) allVertices.get(pid);
line(v.x, v.y, v.z, vpre.v.x, vpre.v.y, vpre.v.z);
}
}
void displayRainflowDir_vector() {
stroke(0);
strokeWeight(2);
Vertex vnT= (Vertex) allVertices.get(tID);
Vec3D vnDir= vnT.v.sub(v);
Vec3D vT= v.add(vnDir.normalizeTo(10));
line(v.x, v.y, v.z, vT.x, vT.y, vT.z);
}
void displayRainflowDir() {
stroke(0);
strokeWeight(2);
Vertex vnT= (Vertex) allVertices.get(tID);
line(v.x, v.y, v.z, vnT.v.x, vnT.v.y, vnT.v.z);
}
void displayTargetDir() {
stroke(255, 0, 0);
strokeWeight(1);
Vec3D vt= v.add(targetDir.scale(10));
line(v.x, v.y, v.z, vt.x, vt.y, vt.z);
}
//======================================================================================
}