source: issm/trunk-jpl/src/c/shared/Numerics/XZvectorsToCoordinateSystem.cpp@ 12476

Last change on this file since 12476 was 12476, checked in by utke, 13 years ago

type renames

File size: 1.6 KB
Line 
1#include "../Alloc/alloc.h"
2#include "../../include/include.h"
3#include "../Exceptions/exceptions.h"
4#include "./isnan.h"
5#include <math.h>
6
7void XZvectorsToCoordinateSystem(IssmDouble* T,IssmDouble* xzvectors){
8
9 int i,j;
10 IssmDouble x[3],y[3],z[3];
11 IssmDouble x_norm, y_norm, z_norm;
12
13 for(i=0;i<6;i++){
14 if(isnan(xzvectors[i])){
15 /*At least one NaN found: default to Id*/
16 T[0*3+0] = 1.0; T[0*3+1] = 0.0; T[0*3+2] = 0.0;
17 T[1*3+0] = 0.0; T[1*3+1] = 1.0; T[1*3+2] = 0.0;
18 T[2*3+0] = 0.0; T[2*3+1] = 0.0; T[2*3+2] = 1.0;
19
20 return;
21 }
22 }
23
24 /* get input {x} (vector in local x-z plane): */
25 x[0] = xzvectors[0];
26 x[1] = xzvectors[1];
27 x[2] = xzvectors[2];
28
29 /* get input {z} (local tangent plane normal vector): */
30 z[0] = xzvectors[3];
31 z[1] = xzvectors[4];
32 z[2] = xzvectors[5];
33
34 /* compute {y} = {z} x {x}: */
35 y[0] = x[2]*z[1] - x[1]*z[2];
36 y[1] = -x[2]*z[0] + x[0]*z[2];
37 y[2] = x[1]*z[0] - x[0]*z[1];
38
39 /* normalise {x}, {y} and {z} to form unit vectors {i_hat}, {j_hat} and {k_hat};
40 store in {x}, {y}, and {z}: */
41 x_norm = sqrt( x[0]*x[0] + x[1]*x[1] + x[2]*x[2]);
42 y_norm = sqrt( y[0]*y[0] + y[1]*y[1] + y[2]*y[2]);
43 z_norm = sqrt( z[0]*z[0] + z[1]*z[1] + z[2]*z[2]);
44
45 x[0] = x[0]/x_norm; x[1] = x[1]/x_norm; x[2] = x[2]/x_norm;
46 y[0] = y[0]/y_norm; y[1] = y[1]/y_norm; y[2] = y[2]/y_norm;
47 z[0] = z[0]/z_norm; z[1] = z[1]/z_norm; z[2] = z[2]/z_norm;
48
49 /* Tlg columns are just {i_hat}, {j_hat} and {k_hat}, respectively: */
50 T[0*3+0] = x[0]; T[0*3+1] = y[0]; T[0*3+2] = z[0];
51 T[1*3+0] = x[1]; T[1*3+1] = y[1]; T[1*3+2] = z[1];
52 T[2*3+0] = x[2]; T[2*3+1] = y[2]; T[2*3+2] = z[2];
53}
Note: See TracBrowser for help on using the repository browser.