Code_TYMPAN  4.4.0
Industrial site acoustic simulation
Repere.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (C) <2012> <EDF-R&D> <FRANCE>
3  * This program is free software; you can redistribute it and/or modify
4  * it under the terms of the GNU General Public License as published by
5  * the Free Software Foundation; either version 2 of the License, or
6  * (at your option) any later version.
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10  * See the GNU General Public License for more details.
11  * You should have received a copy of the GNU General Public License along
12  * with this program; if not, write to the Free Software Foundation, Inc.,
13  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
14  */
15 
16 #include "Repere.h"
17 
18 Repere::Repere(vec3 _U, vec3 _V, vec3 _W, vec3 _O) : Base()
19 {
20 
21  name = "unknonw repere";
22 
23  U = vec3(_U);
24  V = vec3(_V);
25  W = vec3(_W);
26  O = vec3(_O);
27 
29 }
30 
31 Repere::Repere(const Repere& repere) : Base(repere)
32 {
33  U = vec3(repere.U);
34  V = vec3(repere.V);
35  W = vec3(repere.W);
36  O = vec3(repere.O);
37 
39 }
40 
42 {
43 
44  // Matrice du repere local vers global
45  LtoG[0][0] = U.x;
46  LtoG[0][1] = V.x;
47  LtoG[0][2] = W.x;
48  LtoG[0][3] = O.x;
49  LtoG[1][0] = U.y;
50  LtoG[1][1] = V.y;
51  LtoG[1][2] = W.y;
52  LtoG[1][3] = O.y;
53  LtoG[2][0] = U.z;
54  LtoG[2][1] = V.z;
55  LtoG[2][2] = W.z;
56  LtoG[2][3] = O.z;
57  LtoG[3][0] = 0.0;
58  LtoG[3][1] = 0.0;
59  LtoG[3][2] = 0.0;
60  LtoG[3][3] = 1.0;
61 
62  // Matrice du repere global vers local
63  // On suppose qu'on travaille avec des reperes orthonorme. Donc le passage d'un repere a l'autre est une
64  // translation et une rotation. L'inverse de la matrice de rotation est sa transposee L'inverse de la
65  // translation est la negation de la matrice de translation
66  GtoL[0][0] = U.x;
67  GtoL[0][1] = U.y;
68  GtoL[0][2] = U.z;
69  GtoL[0][3] = -U.x * O.x - U.y * O.y - U.z * O.z;
70  GtoL[1][0] = V.x;
71  GtoL[1][1] = V.y;
72  GtoL[1][2] = V.z;
73  GtoL[1][3] = -V.x * O.x - V.y * O.y - V.z * O.z;
74  GtoL[2][0] = W.x;
75  GtoL[2][1] = W.y;
76  GtoL[2][2] = W.z;
77  GtoL[2][3] = -W.x * O.x - W.y * O.y - W.z * O.z;
78  GtoL[3][0] = 0.0;
79  GtoL[3][1] = 0.0;
80  GtoL[3][2] = 0.0;
81  GtoL[3][3] = 1.0;
82 }
83 
85 {
86  vec3 result;
87  result.x = local.x * LtoG[0][0] + local.y * LtoG[0][1] + local.z * LtoG[0][2];
88  result.y = local.x * LtoG[1][0] + local.y * LtoG[1][1] + local.z * LtoG[1][2];
89  result.z = local.x * LtoG[2][0] + local.y * LtoG[2][1] + local.z * LtoG[2][2];
90 
91  return result;
92 }
93 
95 {
96  vec3 result;
97  result.x = global.x * GtoL[0][0] + global.y * GtoL[0][1] + global.z * GtoL[0][2];
98  result.y = global.x * GtoL[1][0] + global.y * GtoL[1][1] + global.z * GtoL[1][2];
99  result.z = global.x * GtoL[2][0] + global.y * GtoL[2][1] + global.z * GtoL[2][2];
100 
101  return result;
102 }
103 
105 {
106  vec4 local4 = vec4(local);
107  vec4 result4;
108 
109  result4.x = local4.x * LtoG[0][0] + local4.y * LtoG[0][1] + local4.z * LtoG[0][2] + local4.w * LtoG[0][3];
110  result4.y = local4.x * LtoG[1][0] + local4.y * LtoG[1][1] + local4.z * LtoG[1][2] + local4.w * LtoG[1][3];
111  result4.z = local4.x * LtoG[2][0] + local4.y * LtoG[2][1] + local4.z * LtoG[2][2] + local4.w * LtoG[2][3];
112  result4.w = local4.x * LtoG[3][0] + local4.y * LtoG[3][1] + local4.z * LtoG[3][2] + local4.w * LtoG[3][3];
113 
114  vec3 result = vec3(result4.x / result4.w, result4.y / result4.w, result4.z / result4.w);
115 
116  return result;
117 }
118 
120 {
121  vec4 global4 = vec4(global);
122  vec4 result4;
123 
124  result4.x =
125  global4.x * GtoL[0][0] + global4.y * GtoL[0][1] + global4.z * GtoL[0][2] + global4.w * GtoL[0][3];
126  result4.y =
127  global4.x * GtoL[1][0] + global4.y * GtoL[1][1] + global4.z * GtoL[1][2] + global4.w * GtoL[1][3];
128  result4.z =
129  global4.x * GtoL[2][0] + global4.y * GtoL[2][1] + global4.z * GtoL[2][2] + global4.w * GtoL[2][3];
130  result4.w =
131  global4.x * GtoL[3][0] + global4.y * GtoL[3][1] + global4.z * GtoL[3][2] + global4.w * GtoL[3][3];
132 
133  vec3 result = vec3(result4.x / result4.w, result4.y / result4.w, result4.z / result4.w);
134 
135  return result;
136 }
Base class of Event, Material, PostFilter, Ray, Repere, Scene, Shape, Simulation, Source.
Definition: Base.h:25
std::string name
Each instantiated object may be named.
Definition: Base.h:52
Frame class.
Definition: Repere.h:26
vec3 U
Coordinates of local axis U in global frame.
Definition: Repere.h:102
decimal LtoG[4][4]
Local to global frame matrix.
Definition: Repere.h:107
vec3 vectorFromGlobalToLocal(const vec3 &global)
Get local coordinates of vector expressed in global coordinates.
Definition: Repere.cpp:94
vec3 positionFromLocalToGlobal(const vec3 &local)
Get global coordinates of a point expressed in local coordinates.
Definition: Repere.cpp:104
vec3 V
Coordinates of local axis V in global frame.
Definition: Repere.h:103
void updateMatrices()
Update the global and local frame matrices.
Definition: Repere.cpp:41
Repere()
Constructors.
Definition: Repere.h:30
vec3 W
Coordinates of local axis W in global frame.
Definition: Repere.h:104
decimal GtoL[4][4]
Global to local frame matrix.
Definition: Repere.h:108
vec3 vectorFromLocalToGlobal(const vec3 &local)
Get global coordinates of vector expressed in local coordinates.
Definition: Repere.cpp:84
vec3 positionFromGlobalToLocal(const vec3 &global)
Get local coordinates of a point expressed in global coordinates.
Definition: Repere.cpp:119
vec3 O
Origin of the local frame in the global frame.
Definition: Repere.h:105
base_vec3< decimal > vec3
Definition: mathlib.h:381