source: anuga_work/development/anugavis/src/vector.c @ 5272

Last change on this file since 5272 was 5272, checked in by jack, 17 years ago

Added vector module.

File size: 572 bytes
Line 
1#include <math.h>
2#include "vector.h"
3
4float vlen(vector v){
5  return sqrt(v[0] * v[0] + v[1] * v[1] + v[2] * v[2]);
6}
7
8void vsub(vector v1, vector v2, vector result){
9  int i;
10  for(i = 0 ; i < 3 ; i++) result[i] = v1[i] - v2[i];
11}
12
13void vnormalise(vector v, vector result){
14  float len = vlen(v);
15  int i;
16  for(i = 0 ; i < 3 ; i++) result[i] = v[i] / len;
17}
18
19void vcross(vector v1, vector v2, vector result){
20  result[0] = v1[1] * v2[2] - v1[2] * v2[1];
21  result[1] = v1[2] * v2[0] - v1[0] * v2[2];
22  result[2] = v1[0] * v2[1] - v1[1] * v2[0];
23}
Note: See TracBrowser for help on using the repository browser.