[14981] | 1 | #include <math.h>
|
---|
| 2 |
|
---|
[14904] | 3 | #include "../MemOps/MemOps.h"
|
---|
[10367] | 4 | #include "../Exceptions/exceptions.h"
|
---|
[14915] | 5 | #include "../Numerics/types.h"
|
---|
[12152] | 6 | #include "./isnan.h"
|
---|
[10367] | 7 |
|
---|
[12476] | 8 | void XZvectorsToCoordinateSystem(IssmDouble* T,IssmDouble* xzvectors){
|
---|
[10367] | 9 |
|
---|
[12476] | 10 | IssmDouble x[3],y[3],z[3];
|
---|
| 11 | IssmDouble x_norm, y_norm, z_norm;
|
---|
[10367] | 12 |
|
---|
[13758] | 13 | for(int i=0;i<6;i++){
|
---|
[12529] | 14 | if(xIsNan<IssmDouble>(xzvectors[i])){
|
---|
[10367] | 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 | }
|
---|