X-Git-Url: https://www.hackdaworld.org/gitweb/?a=blobdiff_plain;f=math%2Fmath.c;fp=math%2Fmath.c;h=6d707e93bd7c23b355d8292273349fb37c004d30;hb=710717c4033bc5b8eb34644914e762a2834ae345;hp=0000000000000000000000000000000000000000;hpb=6eb09b305eb6f565d844979b68dd2542e9a0d5fa;p=physik%2Fposic.git diff --git a/math/math.c b/math/math.c new file mode 100644 index 0000000..6d707e9 --- /dev/null +++ b/math/math.c @@ -0,0 +1,66 @@ +/* + * math.c - basic vector calculations + * + * author: Frank Zirkelbach + * + */ + + +#include +#include "math.h" + +int v3_add(t_3dvec *sum,t_3dvec *a,t_3dvec *b) { + + sum->x=a->x+b->x; + sum->y=a->y+b->y; + sum->z=a->z+b->z; + + return 0; +} + +int v3_sub(t_3dvec *sum,t_3dvec *a,t_3dvec *b) { + + sum->x=a->x-b->x; + sum->y=a->y-b->y; + sum->z=a->z-b->z; + + return 0; +} + +int v3_scale(t_3dvec *result,t_3dvec *a,double s) { + + result->x=s*a->x; + result->y=s*a->y; + result->z=s*a->z; + + return 0; +} + +int v3_zero(t_3dvec *vec) { + + vec->x=.0; + vec->y=.0; + vec->z=.0; + + return 0; +} + +int v3_set(t_3dvec *vec,double *ptr) { + + memcpy(vec,ptr,sizeof(t_3dvec)); + + return 0; +} + +int v3_copy(t_3dvec *trg,t_3dvec *src) { + + memcpy(trg,src,sizeof(t_3dvec)); + + return 0; +} + +int v3_cmp(t_3dvec *a,t_3dvec *b) { + + return(memcmp(a,b,sizeof(t_3dvec))); +} +