-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlink.cpp
More file actions
163 lines (127 loc) · 2.87 KB
/
link.cpp
File metadata and controls
163 lines (127 loc) · 2.87 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
160
161
162
163
#include "link.h"
LinkAhhh::LinkAhhh() {
a[0] = 1;
for(int i = 1; i < 4; i++)
a[i] = 0;
}
LinkAhhh::LinkAhhh(double* initA) {
for(int i = 0; i < 4; i++)
a[i] = initA[i];
}
LinkAhhh::LinkAhhh(const LinkAhhh& U2) {
for(int i = 0; i < 4; i++)
a[i] = U2.a[i];
}
LinkAhhh::LinkAhhh(const LinkAhhh&& U2) {
for(int i = 0; i < 4; i++)
a[i] = U2.a[i];
}
LinkAhhh LinkAhhh::inv() const {
double norm2 = this->det();
double invA[4] = {a[0]/norm2, -a[1]/norm2, -a[2]/norm2, -a[3]/norm2};
LinkAhhh inv(invA);
return inv;
}
double LinkAhhh::det() const {
return a[0]*a[0] + a[1]*a[1] + a[2]*a[2] + a[3]*a[3];
}
double LinkAhhh::tr() const {
return 2*a[0];
}
LinkAhhh LinkAhhh::scale(const double s) {
double newA[4];
for(int i = 0; i < 4; i++)
newA[i] = a[i] * s;
LinkAhhh scaled(newA);
return scaled;
}
void LinkAhhh::setA(const double* newA) {
for(int i = 0; i < 4; i++)
a[i] = newA[i];
}
void LinkAhhh::getA(double* targetA) const {
for(int i = 0; i < 4; i++)
targetA[i] = a[i];
}
LinkAhhh LinkAhhh::operator=(const LinkAhhh& U2) {
if (this != &U2)
for(int i = 0; i < 4; i++)
a[i] = U2.a[i];
return *this;
}
LinkAhhh LinkAhhh::operator=(const LinkAhhh&& U2) {
if (this != &U2)
for(int i = 0; i < 4; i++)
a[i] = U2.a[i];
return *this;
}
LinkAhhh LinkAhhh::operator+=(const LinkAhhh& U2) {
double U2a[4];
U2.getA(U2a);
for(int i = 0; i < 4; i++)
a[i] += U2a[i];
return *this;
}
LinkAhhh LinkAhhh::operator+(const LinkAhhh& U2) const{
double sumA[4];
double U2a[4];
U2.getA(U2a);
for(int i = 0; i < 4; i++)
sumA[i] = a[i] + U2a[i];
LinkAhhh sum(sumA);
return sum;
}
LinkAhhh LinkAhhh::operator-=(const LinkAhhh& U2) {
double U2a[4];
U2.getA(U2a);
for(int i = 0; i < 4; i++)
a[i] -= U2a[i];
return *this;
}
LinkAhhh LinkAhhh::operator-(const LinkAhhh& U2) const{
double diffA[4];
double U2a[4];
U2.getA(U2a);
for(int i = 0; i < 4; i++)
diffA[i] = a[i] - U2a[i];
LinkAhhh diff(diffA);
return diff;
}
LinkAhhh LinkAhhh::operator*=(const LinkAhhh& U2) {
double a1 = a[0];
double b1 = a[3];
double c1 = a[2];
double d1 = a[1];
double U2a[4];
U2.getA(U2a);
double a2 = U2a[0];
double b2 = U2a[3];
double c2 = U2a[2];
double d2 = U2a[1];
double prodA[4];
prodA[0] = a1*a2 - b1*b2 - c1*c2 - d1*d2;
prodA[3] = a1*b2 + b1*a2 + c1*d2 - d1*c2;
prodA[2] = a1*c2 - b1*d2 + c1*a2 + d1*b2;
prodA[1] = a1*d2 + b1*c2 - c1*b2 + d1*a2;
this->setA(prodA);
return *this;
}
LinkAhhh LinkAhhh::operator*(const LinkAhhh& U2) const{
double prodA[4];
double a1 = a[0];
double b1 = a[3];
double c1 = a[2];
double d1 = a[1];
double U2a[4];
U2.getA(U2a);
double a2 = U2a[0];
double b2 = U2a[3];
double c2 = U2a[2];
double d2 = U2a[1];
prodA[0] = a1*a2 - b1*b2 - c1*c2 - d1*d2;
prodA[3] = a1*b2 + b1*a2 + c1*d2 - d1*c2;
prodA[2] = a1*c2 - b1*d2 + c1*a2 + d1*b2;
prodA[1] = a1*d2 + b1*c2 - c1*b2 + d1*a2;
LinkAhhh prod(prodA);
return prod;
}