1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
|
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#define PI 3.1415926
float magnitude(float x[3])
{
return sqrt(x[0]*x[0]+x[1]*x[1]+x[2]*x[2]);
}
float dot(float x[3], float y[3])
{
return x[0]*y[0]+x[1]*y[1]+x[2]*y[2];
}
float cross(float x[3], float y[3])
{
return x[1]*y[2]-x[2]*y[1],x[2]*y[0]-x[0]*y[2],x[1]*y[2]-x[2]*y[1];
}
int main (void)
{
float a[]={3,1,2};
float b[]={1,2,3};
printf("\n %f \n",dot(a,b));
printf("\n %f \n",cross(a,b));
return 0;
} |
Partager