-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpoint3d.cpp
More file actions
159 lines (144 loc) · 3.77 KB
/
point3d.cpp
File metadata and controls
159 lines (144 loc) · 3.77 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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
#include "point3d.h"
#include <math.h>
#include <QDebug>
std::vector<std::vector<double> > multiply (const std::vector<std::vector<double> > &a, const std::vector<std::vector<double> >&b)
{
std::vector<std::vector<double> > result;
if (a[0].size()!=b.size()) return result;
std::vector<double> tmp;
double s=0;
for (unsigned i=0;i<a.size(); i++)
{
for (unsigned j=0;i<b[0].size();j++)
{
for (unsigned k=0;k<a[0].size();k++)
s+=a[i][k]*b[k][j];
tmp.push_back(s);
s=0;
}
result.push_back(tmp);
tmp.clear();
}
return result;
}
std::vector <double> Point3D::vector4D ()
{
std::vector <double> result;
result.push_back(x());
result.push_back(y());
result.push_back(z());
result.push_back(1);
return result;
}
Point3D Point3D::rotateXYZ(double a, double b, double c)
{
Point3D point;
point.setX(x());
point.setY(y()*cos(a)-z()*sin(a));
point.setZ(y()*sin(a)+z()*cos(a));
point.setX(point.x()*cos(b)-point.y()*sin(b));
point.setY(point.y());
point.setZ(point.x()*sin(b)+point.z()*cos(b));
point.setX(point.x()*cos(c)-point.y()*sin(c));
point.setY(point.x()*sin(c)+point.y()*cos(c));
point.setZ(point.z());
return point;
}
Point3D Point3D::rotateCustom(const QVector3D & axis, double angle)
{
double b = acos (axis.z()/sqrt(axis.x()*axis.x()+axis.z()*axis.z()));
double a = acos (sqrt(axis.x()*axis.x()+axis.z()*axis.z())/axis.length());
// qDebug()<<"alfa"<<a*180/M_PI;
// qDebug()<<"beta"<<b*180/M_PI;
Point3D point = rotateXYZ(0.0,b,0.0);
point = point.rotateXYZ(a,0.0,0.0);
point= point.rotateXYZ(0.0,0.0,angle);
point= point.rotateXYZ(-a,0.0,0.0);
point= point.rotateXYZ(0.0,-b,0.0);
return point;
}
std::vector <Point3D> Point3D::makePoints (int a1,int a2, int a3, double dz)
{
std::vector <Point3D> result;
double Rxy= a/sqrt(3);
double A1=a1*M_PI/180;
double A2=a2*M_PI/180;
double A3=a3*M_PI/180;
double Dz=sqrt(6)*a/4;
result.push_back(Point3D(x()+Rxy*cos(A1),y()+Rxy*sin(A1),z()+dz));
result.push_back(Point3D(x()+Rxy*cos(A2),y()+Rxy*sin(A2),z()+dz));
if (a3==-1 || a3==1)
{
result.push_back(Point3D(x(),y(),z()+a3*Dz));
qDebug()<<"vertshift";
}
else
result.push_back(Point3D(x()+Rxy*cos(A3),y()+Rxy*sin(A3),z()+dz));
return result;
}
std::vector <Point3D> Point3D::createNextPoints(Point3D &prevP)
{
double dz;
QVector3D shift (x()-prevP.x(),y()-prevP.y(),z()-prevP.z());
shift.normalize();
qDebug()<<"shift"<<shift;
if (fabs(shift.x())<1e-5)
{
if (fabs(shift.y())<1e-5)
{
if (shift.z()>0)
{
dz=sqrt(6)*a/12;
return makePoints(-90,30,150,dz);
}
if (shift.z()<0)
{
dz=-sqrt(6)*a/12;
return makePoints(90,-30,-150,dz);
}
}
if (shift.y()>0)
{
if (shift.z()<0)
{dz=sqrt(6)*a/12; return makePoints(30,150,-1,dz);}
else
{dz=-sqrt(6)*a/12; return makePoints(30,150,1,dz);}
}
if (shift.y()<0)
{
if (shift.z()<0)
{dz=sqrt(6)*a/12;return makePoints(-30,-150,-1,dz);}
else {dz=-sqrt(6)*a/12;return makePoints(-30,-150,1,dz);}
}
}
if (shift.x()>0)
{
if (shift.y()>0)//30
{
if (shift.z()<0)
{dz=sqrt(6)*a/12;return makePoints(-30,90,-1,dz);}
else {dz=-sqrt(6)*a/12;return makePoints(-30,90,1,dz);}
}
if (shift.y()<0) //-30
{
if (shift.z()<0)
{dz=sqrt(6)*a/12;return makePoints(-90,30,-1,dz);}
else {dz=-sqrt(6)*a/12;return makePoints(-90,30,1,dz);}
}
}
if (shift.x()<0)
{
if (shift.y()>0) //-150
{
if (shift.z()>0)
{dz=-sqrt(6)*a/12;return makePoints(-150,90,1,dz);}
else {dz=sqrt(6)*a/12;return makePoints(-150,90,-1,dz);}
}
if (shift.y()<0)//150
{
if (shift.z()<0)
{dz=sqrt(6)*a/12;return makePoints(150,-90,-1,dz);}
else {dz=-sqrt(6)*a/12;return makePoints(150,-90,1,dz);}
}
}
}