rl_basicray  1.0.12
rl_RayMath.h
1 #ifndef rl_RayMath_h_INCLUDED
2 #define rl_RayMath_h_INCLUDED
3 
4 // File: rl_RayMath.h
5 // Author: Terry Gaetz
6 
7 /* --8<--8<--8<--8<--
8  *
9  * Copyright (C) 2006 Smithsonian Astrophysical Observatory
10  *
11  * This file is part of rl_ray
12  *
13  * rl_ray is free software; you can redistribute it and/or
14  * modify it under the terms of the GNU General Public License
15  * as published by the Free Software Foundation; either version 2
16  * of the License, or (at your option) any later version.
17  *
18  * rl_ray is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21  * GNU General Public License for more details.
22  *
23  * You should have received a copy of the GNU General Public License
24  * along with this program; if not, write to the
25  * Free Software Foundation, Inc.
26  * 51 Franklin Street, Fifth Floor
27  * Boston, MA 02110-1301, USA
28  *
29  * -->8-->8-->8-->8-- */
30 
31 /****************************************************************************
32  * Description: collection of methods for rl_RayMath
33  *
34  * History
35  *--------
36  * 1.0.1 2004-Dec-07 tjg simplify/remove include guards
37  * 0.0.0 1998-Jan-30 tjg original version
38  */
39 
40 #include <dvm3/dvm3_rotmat.h> // dvm3_RotMat
41 
42 //########################################################################
43 // rl_RayMath
44 //########################################################################
92 {
93 public:
94 
101  inline static void rotate( dvm3_RotMat const& rotmat,
102  dvm3_Vector& vector );
103 
110  inline static void rotate( dvm3_RotMat const& rotmat,
111  double vector[] );
112 
120  inline static void derotate( dvm3_RotMat const& rotmat,
121  dvm3_Vector& vector );
122 
130  inline static void derotate( dvm3_RotMat const& rotmat,
131  double vector[] );
132 
140  inline static void translate_rotate( dvm3_Vector const& trans,
141  dvm3_RotMat const& rotmat,
142  dvm3_Vector& vector );
143 
151  inline static void translate_rotate( double const trans[],
152  dvm3_RotMat const& rotmat,
153  double vector[] );
154 
163  inline static void derotate_detranslate( dvm3_Vector const& trans,
164  dvm3_RotMat const& rotmat,
165  dvm3_Vector& vector );
174  inline static void derotate_detranslate( double const trans[],
175  dvm3_RotMat const& rotmat,
176  double vector[] );
177 };
178 
179 //########################################################################
180 //########################################################################
181 //
182 // # # # # # # # ###### ####
183 // # ## # # # ## # # #
184 // # # # # # # # # # ##### ####
185 // # # # # # # # # # # #
186 // # # ## # # # ## # # #
187 // # # # ###### # # # ###### ####
188 //
189 //########################################################################
190 //########################################################################
191 
192 //=========================================================================
193 // rotate from STD to BCS coordinates
194 
195 //-------------------------------------------------------------------------
196 inline void rl_RayMath::
197 rotate( dvm3_RotMat const& rotmat,
198  dvm3_Vector& vector )
199 {
200  dvm3_Vector tmp( vector );
201  rotmat.mvmult( vector, tmp );
202 }
203 
204 //-------------------------------------------------------------------------
205 inline void rl_RayMath::
206 rotate( dvm3_RotMat const& rotmat,
207  double vector[] )
208 {
209  double tmp[3];
210  vm_V3Math<double>::copy(tmp, vector);
211  rotmat.mvmult( vector, tmp );
212 }
213 
214 //=========================================================================
215 // derotate from BCS back to STD coordinates
216 
217 //-------------------------------------------------------------------------
218 inline void rl_RayMath::
219 derotate( dvm3_RotMat const& rotmat,
220  dvm3_Vector& vector )
221 {
222  dvm3_Vector tmp( vector );
223  rotmat.mtvmult( vector, tmp );
224 }
225 
226 //-------------------------------------------------------------------------
227 inline void rl_RayMath::
228 derotate( dvm3_RotMat const& rotmat,
229  double vector[] )
230 {
231  double tmp[3];
232  vm_V3Math<double>::copy(tmp, vector);
233  rotmat.mtvmult( vector, tmp );
234 }
235 
236 //=========================================================================
237 // translate to to BCS origin; rotate from STD to BCS coordinates
238 
239 //-------------------------------------------------------------------------
240 inline void rl_RayMath::
241 translate_rotate( dvm3_Vector const& trans,
242  dvm3_RotMat const& rotmat,
243  dvm3_Vector& vector )
244 {
245  vector += trans;
246  dvm3_Vector tmp( vector );
247  rotmat.mvmult( vector, tmp );
248 }
249 
250 //-------------------------------------------------------------------------
251 inline void rl_RayMath::
252 translate_rotate( double const trans[],
253  dvm3_RotMat const& rotmat,
254  double vector[] )
255 {
256  vm_V3Math<double>::add_eq( vector, trans );
257  double tmp[3];
258  vm_V3Math<double>::copy(tmp, vector);
259  rotmat.mvmult( vector, tmp );
260 }
261 
262 //=========================================================================
263 // derotate from BCS back to STD coordinates; detranslate back to STD origin
264 
265 //-------------------------------------------------------------------------
266 inline void rl_RayMath::
267 derotate_detranslate( dvm3_Vector const& trans,
268  dvm3_RotMat const& rotmat,
269  dvm3_Vector& vector )
270 {
271  dvm3_Vector tmp( vector );
272  rotmat.mtvmult( vector, tmp );
273  vector -= trans;
274 }
275 
276 //-------------------------------------------------------------------------
277 inline void rl_RayMath::
278 derotate_detranslate( double const trans[],
279  dvm3_RotMat const& rotmat,
280  double vector[] )
281 {
282  double tmp[3];
283  vm_V3Math<double>::copy(tmp, vector);
284  rotmat.mtvmult( vector, tmp );
285  vm_V3Math<double>::sub_eq( vector, trans );
286 }
287 
288 // rl_RayMath.h
289 #endif
static void derotate_detranslate(dvm3_Vector const &trans, dvm3_RotMat const &rotmat, dvm3_Vector &vector)
Rotate from BCS to STD coordinates, then translate back to original position.
Definition: rl_RayMath.h:267
A class gathering together static methods for operations on ray position or direction vectors.
Definition: rl_RayMath.h:91
static void translate_rotate(dvm3_Vector const &trans, dvm3_RotMat const &rotmat, dvm3_Vector &vector)
Translate to BCS origin, then rotate from STD to BCS coordinates.
Definition: rl_RayMath.h:241
static void derotate(dvm3_RotMat const &rotmat, dvm3_Vector &vector)
De-rotate vector from BCS coordinates back to STD coordinates.
Definition: rl_RayMath.h:219
static void rotate(dvm3_RotMat const &rotmat, dvm3_Vector &vector)
Rotate vector from STD coordinates to BCS coordinates.
Definition: rl_RayMath.h:197