/** * \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; }
/* * Given vectors a and b, compute the angle between them in degrees */ double Lgm_VectorAngle(Lgm_Vector *a, Lgm_Vector *b) { double ang; Lgm_Vector u, v; u = *a; v = *b; Lgm_NormalizeVector(&u); Lgm_NormalizeVector(&v); ang = acos(Lgm_DotProduct(&u, &v)); return (ang*DegPerRad); }
/** * \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 }