Skip to content

Commit

Permalink
Normalize quats
Browse files Browse the repository at this point in the history
  • Loading branch information
marinerhemant committed Oct 26, 2023
1 parent e07a7c9 commit c15dd3a
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions FF_HEDM/src/GetMisorientation.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,14 @@
#define deg2rad 0.0174532925199433
#define rad2deg 57.2957795130823

static inline void normalizeQuat(double quat[4]){
double norm = sqrt(quat[0]*quat[0]+quat[1]*quat[1]+quat[2]*quat[2]+quat[3]*quat[3]);
quat[0] /= norm;
quat[1] /= norm;
quat[2] /= norm;
quat[3] /= norm;
}

double TricSym[2][4] = { // This is just for house keeping to make it 2 rows
{1.00000, 0.00000, 0.00000, 0.00000},
{1.00000, 0.00000, 0.00000, 0.00000}};
Expand Down Expand Up @@ -192,6 +200,7 @@ void BringDownToFundamentalRegionSym(double QuatIn[4], double QuatOut[4], int Nr
QuatOut[1] = qps[maxCosRowNr][1];
QuatOut[2] = qps[maxCosRowNr][2];
QuatOut[3] = qps[maxCosRowNr][3];
normalizeQuat(QuatOut);
}

inline
Expand Down Expand Up @@ -269,14 +278,7 @@ void BringDownToFundamentalRegion(double QuatIn[4], double QuatOut[4],int SGNr)
QuatOut[1] = qps[maxCosRowNr][1];
QuatOut[2] = qps[maxCosRowNr][2];
QuatOut[3] = qps[maxCosRowNr][3];
}

static inline void normalizeQuat(double quat[4]){
double norm = sqrt(quat[0]*quat[0]+quat[1]*quat[1]+quat[2]*quat[2]+quat[3]*quat[3]);
quat[0] /= norm;
quat[1] /= norm;
quat[2] /= norm;
quat[3] /= norm;
normalizeQuat(QuatOut);
}

inline
Expand All @@ -287,6 +289,8 @@ double GetMisOrientation(double quat1[4], double quat2[4], double axis[3], doubl
normalizeQuat(quat2);
BringDownToFundamentalRegion(quat1,q1FR,SGNr);
BringDownToFundamentalRegion(quat2,q2FR,SGNr);
normalizeQuat(q1FR);
normalizeQuat(q2FR);
q1Inv[0] = -q1FR[0];
q1Inv[1] = q1FR[1];
q1Inv[2] = q1FR[2];
Expand Down Expand Up @@ -316,6 +320,8 @@ double GetMisOrientationAngle(double quat1[4], double quat2[4], double *Angle, i
normalizeQuat(quat2);
BringDownToFundamentalRegionSym(quat1,q1FR,NrSymmetries,Sym);
BringDownToFundamentalRegionSym(quat2,q2FR,NrSymmetries,Sym);
normalizeQuat(q1FR);
normalizeQuat(q2FR);
q1FR[0] = -q1FR[0];
QuaternionProduct(q1FR,q2FR,QP);
BringDownToFundamentalRegionSym(QP,MisV,NrSymmetries,Sym);
Expand Down

0 comments on commit c15dd3a

Please sign in to comment.