/** * \brief * Compute the curl of B and it's parallel and perpendicular components at a given point. * * \details * Computes \f$ \nabla\times B \f$, \f$ (\nabla\times B)_\parallel \f$, and \f$ (\nabla\times B)_\perp \f$. * * * \param[in] u0 Position (in GSM) to use. * \param[out] CurlB The computed curl of B at position u0. * \param[out] CurlB_para The computed parallel component of curl of B at position u0. * \param[out] CurlB_perp The computed perpendicular component of curl of B at position u0. * \param[in] DerivScheme Derivative scheme to use (can be one of LGM_DERIV_SIX_POINT, LGM_DERIV_FOUR_POINT, or LGM_DERIV_TWO_POINT). * \param[in] h The delta (in Re) to use for grid spacing in the derivative scheme. * \param[in,out] m A properly initialized and configured Lgm_MagModelInfo structure. * * * \author Mike Henderson * \date 2011 * */ void Lgm_CurlB2( Lgm_Vector *u0, Lgm_Vector *CurlB, Lgm_Vector *CurlB_para, Lgm_Vector *CurlB_perp, int DerivScheme, double h, Lgm_MagModelInfo *m ) { double g; Lgm_Vector Bvec; Lgm_CurlB( u0, CurlB, DerivScheme, h, m ); m->Bfield( u0, &Bvec, m ); Lgm_NormalizeVector( &Bvec ); // Compute parallel component of CurlB g = Lgm_DotProduct( &Bvec, CurlB ); *CurlB_para = *CurlB; Lgm_ScaleVector( CurlB_para, g ); // Compute perpendicular component of CurlB (CurlB_perp = CurlB - CurlB_para) Lgm_VecSub( CurlB_perp, CurlB, CurlB_para ); return; }
/** * \brief * Compute the gradient of B and it's parallel and perpendicular components at a given point. * * \details * Computes \f$ \nabla B \f$, \f$ (\nabla B)_\parallel \f$, and \f$ (\nabla B)_\perp \f$. * * * \param[in] u0 Position (in GSM) to use. * \param[out] GradB The computed curl of B at position u0. * \param[out] GradB_para The computed parallel component of curl of B at position u0. * \param[out] GradB_perp The computed perpendicular component of curl of B at position u0. * \param[in] DerivScheme Derivative scheme to use (can be one of LGM_DERIV_SIX_POINT, LGM_DERIV_FOUR_POINT, or LGM_DERIV_TWO_POINT). * \param[in] h The delta (in Re) to use for grid spacing in the derivative scheme. * \param[in,out] m A properly initialized and configured Lgm_MagModelInfo structure. * * * \author Mike Henderson * \date 2011 * */ void Lgm_GradB2( Lgm_Vector *u0, Lgm_Vector *GradB, Lgm_Vector *GradB_para, Lgm_Vector *GradB_perp, int DerivScheme, double h, Lgm_MagModelInfo *m ) { double g; Lgm_Vector Bvec; Lgm_GradB( u0, GradB, DerivScheme, h, m ); m->Bfield( u0, &Bvec, m ); Lgm_NormalizeVector( &Bvec ); // Compute parallel component of GradB g = Lgm_DotProduct( &Bvec, GradB ); *GradB_para = *GradB; Lgm_ScaleVector( GradB_para, g ); // Compute perpendicular component of GradB (GradB_perp = GradB - GradB_para) Lgm_VecSub( GradB_perp, GradB, GradB_para ); return; }
/** * \brief * Initialize a Lgm_SlerpInfo structure. * \details * This routine computes \f$\sin(\phi)\f$, \f$\cos(\phi)\f$, and * \f$\phi\f$. Where \f$\phi\f$ is the angle between the initial and final * unit vectors. This is done outside the main slerp routine because you * may want to perform many interps with the same endpoint vectors. * * \param[in] a: initial unit vector. * \param[in] b: final unit vector. * * \param[in,out] si: Lgm_SlerpInfo structure. * */ void Lgm_InitSlerp( Lgm_Vector *a, Lgm_Vector *b, Lgm_SlerpInfo *si ) { Lgm_Vector v, w; si->CosPhi = Lgm_DotProduct( a, b ); w = *a; Lgm_ScaleVector( &w, si->CosPhi ); // w = cos(phi)*a-hat Lgm_VecSub( &v, b, &w ); // v = b-hat - cos(phi)*a-hat si->SinPhi = Lgm_Magnitude( &v ); // sin(phi) si->Phi = atan2( si->SinPhi, si->CosPhi ); // Phi }
int main(){ Lgm_Vector a, b, z1, z2; Lgm_SlerpInfo s; double alpha; a.x = 1.0; a.y = 1.0; a.z = 1.0; b.x = 0.0; b.y = -1.0; b.z = 1.0; Lgm_NormalizeVector( &a ); Lgm_NormalizeVector( &b ); Lgm_InitSlerp( &a, &b, &s ); alpha = 0.1; Lgm_Slerp( &a, &b, &z1, alpha, &s ); printf("Results of slerping:\n"); Lgm_PrintVector(&a); Lgm_PrintVector(&b); Lgm_PrintVector(&z1); z2.x = (1.0-alpha)*a.x + alpha*b.x; z2.y = (1.0-alpha)*a.y + alpha*b.y; z2.z = (1.0-alpha)*a.z + alpha*b.z; Lgm_NormalizeVector( &z2 ); printf("Results of interpolating components (and re-normalizing):\n"); Lgm_PrintVector(&a); Lgm_PrintVector(&b); Lgm_PrintVector(&z2); Lgm_VecSub(&a, &z1, &z2); printf("\nThey are different by:\n"); Lgm_PrintVector(&a); return(0); }
/* * Find Magnitude of difference between to vectors */ double Lgm_VecDiffMag(Lgm_Vector *a, Lgm_Vector *b ) { Lgm_Vector c; Lgm_VecSub( &c, a, b ); // c = a-b return( Lgm_Magnitude( &c ) ); }