/* GW-Vectors.c Vector arithmetic for Gravity-Well Gary Teachout Copyright July 1989 lc -x GW-Vectors To compile with Lattice 5.0 */ #include "GW-Include.h" void rotatedv( v , pv , s , c ) struct dv *v , *pv ; double *s , *c ; { struct dv t1 , t2 ; scaledv( v , c , &t1 ) ; scaledv( pv , s , &t2 ) ; adddv( &t1 , &t2 , v ) ; } void rotatedvpair10( x , y ) /* rotate vector pair 10 degrees */ struct dv *x , *y ; { static double srotate = 0.1736481776669303311 ,/* the sine and cosine */ crotate = 0.9848077530122081313 ,/* of 10 degrees */ m1 = -1.0 ; struct dv t1 ; scaledv( x , &m1 , &t1 ) ; rotatedv( x , y , &srotate , &crotate ) ; rotatedv( y , &t1 , &srotate , &crotate ) ; } void adddv( a , b , out ) struct dv *a , *b , *out ; { out->x = a->x + b->x ; out->y = a->y + b->y ; out->z = a->z + b->z ; } void subdv( a , b , out ) struct dv *a , *b , *out ; { out->x = a->x - b->x ; out->y = a->y - b->y ; out->z = a->z - b->z ; } void scaledv( a , b , out ) struct dv *a , *out ; double *b ; { out->x = a->x * *b ; out->y = a->y * *b ; out->z = a->z * *b ; } void dotdv( a , b , out ) struct dv *a , *b ; double *out ; { *out = a->x * b->x + a->y * b->y + a->z * b->z ; } /**** Gravity-Well does not use cross products void crossdv( a , b , out ) ** output must not go to input ** struct dv *a , *b , *out ; { out->x = a->y * b->z - a->z * b->y ; out->y = a->z * b->x - a->x * b->z ; out->z = a->x * b->y - a->y * b->x ; } ****/ void magdv( a , out ) struct dv *a ; double *out ; { *out = sqrt( a->x * a->x + a->y * a->y + a->z * a->z ) ; } void basis( a , b , out ) /* output must not go to input */ struct dv *a , *out ; struct obv *b ; { dotdv( a , &b->i , &out->x ) ; dotdv( a , &b->j , &out->y ) ; dotdv( a , &b->k , &out->z ) ; }