RicardasSim

vectors dot product 3d

Mar 21st, 2019
630
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.61 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. typedef struct{
  5.     double x;
  6.     double y;
  7.     double z;
  8. }Vector3;
  9.  
  10.  
  11. double vectDotProduct(Vector3 a, Vector3 b)
  12. {    
  13.     return a.x * b.x + a.y * b.y + a.z * b.z;
  14. }
  15.  
  16. int main (int argc, char **argv)
  17. {
  18.  
  19.     Vector3 tstV1 = {1.0,0.0,0.0};
  20.     Vector3 tstV2 = {0.0,1.0,1.0};
  21.     Vector3 tstV3 = {1.0,1.0,1.0};
  22.  
  23.    
  24.     printf("%f\n",vectDotProduct(tstV1,tstV2));
  25.     printf("%f\n",vectDotProduct(tstV1,tstV3));
  26.     printf("%f\n",vectDotProduct(tstV2,tstV3));
  27.     printf("\n");
  28.  
  29.    
  30. return 0;
  31. }
  32.  
  33. /*
  34. output:
  35.  
  36. 0.000000
  37. 1.000000
  38. 2.000000
  39.  
  40. */
Advertisement
Add Comment
Please, Sign In to add comment