-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathNode.cpp
More file actions
145 lines (127 loc) · 3.13 KB
/
Node.cpp
File metadata and controls
145 lines (127 loc) · 3.13 KB
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
#include "Node.h"
#include <time.h>
#include <math.h>
#include <stdlib.h>
#include <cstring>
#include <stdio.h>
#include <iostream>
#define R_I 1000000
#define R_D 1000000.0
using std::cout;
using std::endl;
Node::Node()
{
nextStep = 0;
trianglesNum = 0;
}
Node::Node(double* _c)
{
for (int i=0; i<2; i++)
{
coords[i]=_c[i];
}
nextStep = 0;
trianglesNum = 0;
}
Node::Node(Node* _n)
{
for (int i=0; i<2; i++)
coords[i]=_n->coords[i];
setValues(_n->u);
local_num = _n->local_num;
nextStep = 0;
trianglesNum = _n->trianglesNum;
for (int i=0; i<trianglesNum; i++)
triangles[i]=_n->triangles[i];
for (int i=0; i<4; i++)
axis[i]=_n->axis[i];
for (int i=0; i<4; i++)
axis_neg[i]=_n->axis_neg[i];
//for (int i=0; i<4; i++)
// axis_method[i]=_n->axis_method[i];
// if (local_num == 7) printf("C%d \n", trianglesNum);
}
Node::~Node()
{
//do NOT delete nextStep!
}
double scalar(double* _v1, double* _v2)
{
return _v1[0]*_v2[0]+_v1[1]*_v2[1];
}
double scalar(double _x0, double _y0, double _x1, double _y1)
{
return _x0*_x1+_y0*_y1;
}
void Node::setValues(double* _v)
{
if (!_v) return;
for (int i=0;i<5;i++)
u[i]=_v[i];
}
int Node::addTriangle(Triangle* t)
{
if (!t) return 0;
if (trianglesNum >= 30) return 0;
// if (local_num == 7) printf("A%d \n", trianglesNum);
triangles[trianglesNum] = t;
trianglesNum++;
if (nextStep)
nextStep->addTriangle(t);
// if (local_num == 7) printf("A%d \n", trianglesNum);
return 1;
}
void Node::randomizeAxis()
{
//for (int i=0; i<4; i++)
// axis[i]= sqrt(2.0)/2.0;//0.0;//
//axis[3] = -sqrt(2.0)/2.0;
axis[1] = axis[2] = 0.0;
axis[3] = axis[0] = 1.0;
return;
axis[0] = (0.98 * (rand()%R_I)/R_D + 0.01) * (2.0*(rand()%2) - 1.0);
axis[1] = (0.98 * (rand()%R_I)/R_D + 0.01) * (2.0*(rand()%2) - 1.0);
double norma = sqrt(scalar(axis,axis));
axis[0]/=norma; axis[1]/=norma;
if (fabs(axis[0]) > 0.0)
{
axis[3] = 1.0;
axis[2] = -axis[1]/axis[0];
//printf("norm: %lf %lf %lf\n",norma, axis[2], axis[3]);
}
else if (fabs(axis[1]) > 0.0)
{
axis[2] = 1.0;
axis[3] = -axis[0]/axis[1];
}
else
{
printf("Fail in determining axis direction");
return;
}
norma = sqrt(axis[2]*axis[2]+axis[3]*axis[3]);//scalar(axis+2,axis+2));
axis[2]/=norma; axis[3]/=norma;
//printf("axes randomized with %lf %lf %lf %lf\n",axis[0],axis[1],axis[2],axis[3]);
//check!!!!!
double check[3] = {scalar(axis,axis),scalar(axis+2,axis+2)
,scalar(axis,axis+2)};
// printf ("axis random %.20lf %.20lf %.20lf\n",check[0],check[1],check[2]);
if ((check[0] - 1.0)*(check[0] - 1.0) > 0.0001 || (check[1] - 1.0)*(check[1] - 1.0) > 0.0001 || check[2]*check[2] > 0.0001)
{
printf ("Warning! Recursion in axis random called! %lf %lf %lf %lf %lf %lf %lf\n",check[0],check[1],check[2], axis[0], axis[1], axis[2], axis[3]);
randomizeAxis();
return;
}
}
void Node::negAxis()
{
double d = axis[3]*axis[0] - axis[1]*axis[2];
axis_neg[0] = axis[3]/d;
axis_neg[1] = -axis[1]/d;
axis_neg[2] = -axis[2]/d;
axis_neg[3] = axis[0]/d;
}
void Node::print_axes()
{
cout <<endl<<"axes node "<<local_num<<" are "<<axis[0] <<" "<<axis[1] <<" "<<axis[2] <<" "<<axis[3] <<" ";
}