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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310 | /*=========================================================================
Module: $RCSfile: verdict_defines.hpp,v $
Copyright (c) 2006 Sandia Corporation.
All rights reserved.
See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
/*
* verdict_defines.cpp contains common definitions
*
* This file is part of VERDICT
*
*/
#ifndef VERDICT_DEFINES
#define VERDICT_DEFINES
#include <cmath>
#include "v_vector.h"
#include "VerdictVector.hpp"
enum VerdictBoolean
{
VERDICT_FALSE = 0,
VERDICT_TRUE = 1
};
#define VERDICT_MIN( a, b ) ( ( a ) < ( b ) ? ( a ) : ( b ) )
#define VERDICT_MAX( a, b ) ( ( a ) > ( b ) ? ( a ) : ( b ) )
inline double determinant( double a, double b, double c, double d )
{
return ( ( a ) * ( d ) - ( b ) * ( c ) );
}
inline double determinant( const VerdictVector& v1, const VerdictVector& v2, const VerdictVector& v3 )
{
return v1 % ( v2 * v3 );
}
#define jacobian_matrix( a, b, c, d, e, f, g ) \
double jac_mat_tmp; \
jac_mat_tmp = sqrt( a ); \
if( jac_mat_tmp == 0 ) \
{ \
( d ) = 0; \
( e ) = 0; \
( f ) = 0; \
( g ) = 0; \
} \
else \
{ \
( d ) = jac_mat_tmp; \
( e ) = 0; \
( f ) = ( b ) / jac_mat_tmp; \
( g ) = ( c ) / jac_mat_tmp; \
}
// this assumes that detmw != 0
#define form_t( m11, m21, m12, m22, mw11, mw21, mw12, mw22, detmw, xm11, xm21, xm12, xm22 ) \
xm11 = ( ( m11 ) * ( mw22 ) - ( m12 ) * ( mw21 ) ) / ( detmw ); \
( xm21 ) = ( ( m21 ) * ( mw22 ) - ( m22 ) * ( mw21 ) ) / ( detmw ); \
( xm12 ) = ( ( m12 ) * ( mw11 ) - ( m11 ) * ( mw12 ) ) / ( detmw ); \
( xm22 ) = ( ( m22 ) * ( mw11 ) - ( m21 ) * ( mw12 ) ) / ( detmw );
extern double verdictSqrt2;
inline double normalize_jacobian( double jacobi,
VerdictVector& v1,<--- Parameter 'v1' can be declared with const<--- Parameter 'v1' can be declared with const<--- Parameter 'v1' can be declared with const<--- Parameter 'v1' can be declared with const
VerdictVector& v2,<--- Parameter 'v2' can be declared with const<--- Parameter 'v2' can be declared with const<--- Parameter 'v2' can be declared with const<--- Parameter 'v2' can be declared with const
VerdictVector& v3,<--- Parameter 'v3' can be declared with const<--- Parameter 'v3' can be declared with const<--- Parameter 'v3' can be declared with const<--- Parameter 'v3' can be declared with const
int tet_flag = 0 )
{
double return_value = 0.0;
if( jacobi != 0.0 )
{
double l1, l2, l3, length_product;
// Note: there may be numerical problems if one is a lot shorter
// than the others this way. But scaling each vector before the
// triple product would involve 3 square roots instead of just
// one.
l1 = v1.length_squared();
l2 = v2.length_squared();
l3 = v3.length_squared();
length_product = sqrt( l1 * l2 * l3 );
// if some numerical scaling problem, or just plain roundoff,
// then push back into range [-1,1].
if( length_product < fabs( jacobi ) )
{
length_product = fabs( jacobi );
}
if( tet_flag == 1 )
return_value = verdictSqrt2 * jacobi / length_product;
else
return_value = jacobi / length_product;
}
return return_value;
}
inline double norm_squared( double m11, double m21, double m12, double m22 )
{
return m11 * m11 + m21 * m21 + m12 * m12 + m22 * m22;
}
#define metric_matrix( m11, m21, m12, m22, gm11, gm12, gm22 ) \
gm11 = ( m11 ) * ( m11 ) + ( m21 ) * ( m21 ); \
( gm12 ) = ( m11 ) * ( m12 ) + ( m21 ) * ( m22 ); \
( gm22 ) = ( m12 ) * ( m12 ) + ( m22 ) * ( m22 );
inline int skew_matrix( double gm11,
double gm12,
double gm22,
double det,
double& qm11,
double& qm21,
double& qm12,
double& qm22 )
{
double tmp = sqrt( gm11 * gm22 );
if( tmp == 0 )
{
return false;
}
qm11 = 1;
qm21 = 0;
qm12 = gm12 / tmp;
qm22 = det / tmp;
return true;
}
inline void inverse( const VerdictVector& x1,
const VerdictVector& x2,
const VerdictVector& x3,
VerdictVector& u1,
VerdictVector& u2,
VerdictVector& u3 )
{
double detx = determinant( x1, x2, x3 );
VerdictVector rx1, rx2, rx3;
rx1.set( x1.x(), x2.x(), x3.x() );
rx2.set( x1.y(), x2.y(), x3.y() );
rx3.set( x1.z(), x2.z(), x3.z() );
u1 = rx2 * rx3;
u2 = rx3 * rx1;
u3 = rx1 * rx2;
u1 /= detx;
u2 /= detx;
u3 /= detx;
}
/*
inline void form_T(double a1[3],
double a2[3],
double a3[3],
double w1[3],
double w2[3],
double w3[3],
double t1[3],
double t2[3],
double t3[3] )
{
double x1[3], x2[3], x3[3];
double ra1[3], ra2[3], ra3[3];
x1[0] = a1[0];
x1[1] = a2[0];
x1[2] = a3[0];
x2[0] = a1[1];
x2[1] = a2[1];
x2[2] = a3[1];
x3[0] = a1[2];
x3[1] = a2[2];
x3[2] = a3[2];
inverse(w1,w2,w3,x1,x2,x3);
t1[0] = dot_product(ra1, x1);
t1[1] = dot_product(ra1, x2);
t1[2] = dot_product(ra1, x3);
t2[0] = dot_product(ra2, x1);
t2[0] = dot_product(ra2, x2);
t2[0] = dot_product(ra2, x3);
t3[0] = dot_product(ra3, x1);
t3[0] = dot_product(ra3, x2);
t3[0] = dot_product(ra3, x3);
}
*/
inline void form_Q( const VerdictVector& v1,
const VerdictVector& v2,
const VerdictVector& v3,
VerdictVector& q1,
VerdictVector& q2,
VerdictVector& q3 )
{
double g11, g12, g13, g22, g23, g33;
g11 = v1 % v1;<--- Same expression on both sides of '%'. [+]Finding the same expression on both sides of an operator is suspicious and might indicate a cut and paste or logic error. Please examine this code carefully to determine if it is correct. <--- Same expression on both sides of '%'. [+]Finding the same expression on both sides of an operator is suspicious and might indicate a cut and paste or logic error. Please examine this code carefully to determine if it is correct. <--- Same expression on both sides of '%'. [+]Finding the same expression on both sides of an operator is suspicious and might indicate a cut and paste or logic error. Please examine this code carefully to determine if it is correct. <--- Same expression on both sides of '%'. [+]Finding the same expression on both sides of an operator is suspicious and might indicate a cut and paste or logic error. Please examine this code carefully to determine if it is correct.
g12 = v1 % v2;
g13 = v1 % v3;
g22 = v2 % v2;<--- Same expression on both sides of '%'. [+]Finding the same expression on both sides of an operator is suspicious and might indicate a cut and paste or logic error. Please examine this code carefully to determine if it is correct. <--- Same expression on both sides of '%'. [+]Finding the same expression on both sides of an operator is suspicious and might indicate a cut and paste or logic error. Please examine this code carefully to determine if it is correct. <--- Same expression on both sides of '%'. [+]Finding the same expression on both sides of an operator is suspicious and might indicate a cut and paste or logic error. Please examine this code carefully to determine if it is correct. <--- Same expression on both sides of '%'. [+]Finding the same expression on both sides of an operator is suspicious and might indicate a cut and paste or logic error. Please examine this code carefully to determine if it is correct.
g23 = v2 % v3;
g33 = v3 % v3;<--- Same expression on both sides of '%'. [+]Finding the same expression on both sides of an operator is suspicious and might indicate a cut and paste or logic error. Please examine this code carefully to determine if it is correct. <--- Same expression on both sides of '%'. [+]Finding the same expression on both sides of an operator is suspicious and might indicate a cut and paste or logic error. Please examine this code carefully to determine if it is correct. <--- Same expression on both sides of '%'. [+]Finding the same expression on both sides of an operator is suspicious and might indicate a cut and paste or logic error. Please examine this code carefully to determine if it is correct. <--- Same expression on both sides of '%'. [+]Finding the same expression on both sides of an operator is suspicious and might indicate a cut and paste or logic error. Please examine this code carefully to determine if it is correct.
double rtg11 = sqrt( g11 );
double rtg22 = sqrt( g22 );
double rtg33 = sqrt( g33 );
VerdictVector temp1;
temp1 = v1 * v2;
double cross = sqrt( temp1 % temp1 );
double q11, q21, q31;
double q12, q22, q32;
double q13, q23, q33;
q11 = 1;
q21 = 0;
q31 = 0;
q12 = g12 / rtg11 / rtg22;
q22 = cross / rtg11 / rtg22;
q32 = 0;
q13 = g13 / rtg11 / rtg33;
q23 = ( g11 * g23 - g12 * g13 ) / rtg11 / rtg33 / cross;
temp1 = v2 * v3;
q33 = ( v1 % temp1 ) / rtg33 / cross;
q1.set( q11, q21, q31 );
q2.set( q12, q22, q32 );
q3.set( q13, q23, q33 );
}
inline void product( VerdictVector& a1,<--- Parameter 'a1' can be declared with const<--- Parameter 'a1' can be declared with const<--- Parameter 'a1' can be declared with const<--- Parameter 'a1' can be declared with const
VerdictVector& a2,<--- Parameter 'a2' can be declared with const<--- Parameter 'a2' can be declared with const<--- Parameter 'a2' can be declared with const<--- Parameter 'a2' can be declared with const
VerdictVector& a3,<--- Parameter 'a3' can be declared with const<--- Parameter 'a3' can be declared with const<--- Parameter 'a3' can be declared with const<--- Parameter 'a3' can be declared with const
VerdictVector& b1,<--- Parameter 'b1' can be declared with const<--- Parameter 'b1' can be declared with const<--- Parameter 'b1' can be declared with const<--- Parameter 'b1' can be declared with const
VerdictVector& b2,<--- Parameter 'b2' can be declared with const<--- Parameter 'b2' can be declared with const<--- Parameter 'b2' can be declared with const<--- Parameter 'b2' can be declared with const
VerdictVector& b3,<--- Parameter 'b3' can be declared with const<--- Parameter 'b3' can be declared with const<--- Parameter 'b3' can be declared with const<--- Parameter 'b3' can be declared with const
VerdictVector& c1,
VerdictVector& c2,
VerdictVector& c3 )
{
VerdictVector x1, x2, x3;
x1.set( a1.x(), a2.x(), a3.x() );
x2.set( a1.y(), a2.y(), a3.y() );
x3.set( a1.z(), a2.z(), a3.z() );
c1.set( x1 % b1, x2 % b1, x3 % b1 );
c2.set( x1 % b2, x2 % b2, x3 % b2 );
c3.set( x1 % b3, x2 % b3, x3 % b3 );
}
inline double norm_squared( VerdictVector& x1, VerdictVector& x2, VerdictVector& x3 )<--- Parameter 'x1' can be declared with const<--- Parameter 'x2' can be declared with const<--- Parameter 'x3' can be declared with const<--- Parameter 'x1' can be declared with const<--- Parameter 'x2' can be declared with const<--- Parameter 'x3' can be declared with const<--- Parameter 'x1' can be declared with const<--- Parameter 'x2' can be declared with const<--- Parameter 'x3' can be declared with const<--- Parameter 'x1' can be declared with const<--- Parameter 'x2' can be declared with const<--- Parameter 'x3' can be declared with const
{
return ( x1 % x1 ) + ( x2 % x2 ) + ( x3 % x3 );<--- Same expression on both sides of '%'. [+]Finding the same expression on both sides of an operator is suspicious and might indicate a cut and paste or logic error. Please examine this code carefully to determine if it is correct. <--- Same expression on both sides of '%'. [+]Finding the same expression on both sides of an operator is suspicious and might indicate a cut and paste or logic error. Please examine this code carefully to determine if it is correct. <--- Same expression on both sides of '%'. [+]Finding the same expression on both sides of an operator is suspicious and might indicate a cut and paste or logic error. Please examine this code carefully to determine if it is correct. <--- Same expression on both sides of '%'. [+]Finding the same expression on both sides of an operator is suspicious and might indicate a cut and paste or logic error. Please examine this code carefully to determine if it is correct.
}
inline double skew_x( VerdictVector& q1,
VerdictVector& q2,
VerdictVector& q3,
VerdictVector& qw1,<--- Parameter 'qw1' can be declared with const<--- Parameter 'qw1' can be declared with const<--- Parameter 'qw1' can be declared with const<--- Parameter 'qw1' can be declared with const
VerdictVector& qw2,<--- Parameter 'qw2' can be declared with const<--- Parameter 'qw2' can be declared with const<--- Parameter 'qw2' can be declared with const<--- Parameter 'qw2' can be declared with const
VerdictVector& qw3 )<--- Parameter 'qw3' can be declared with const<--- Parameter 'qw3' can be declared with const<--- Parameter 'qw3' can be declared with const<--- Parameter 'qw3' can be declared with const
{
double normsq1, normsq2, kappa;
VerdictVector u1, u2, u3;
VerdictVector x1, x2, x3;
inverse( qw1, qw2, qw3, u1, u2, u3 );
product( q1, q2, q3, u1, u2, u3, x1, x2, x3 );
inverse( x1, x2, x3, u1, u2, u3 );
normsq1 = norm_squared( x1, x2, x3 );
normsq2 = norm_squared( u1, u2, u3 );
kappa = sqrt( normsq1 * normsq2 );
double skew = 0;
if( kappa > VERDICT_DBL_MIN ) skew = 3 / kappa;
return skew;
}
#endif
|