Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- typedef struct{
- double x;
- double y;
- double z;
- }Vector3;
- double vectDotProduct(Vector3 a, Vector3 b)
- {
- return a.x * b.x + a.y * b.y + a.z * b.z;
- }
- int main (int argc, char **argv)
- {
- Vector3 tstV1 = {1.0,0.0,0.0};
- Vector3 tstV2 = {0.0,1.0,1.0};
- Vector3 tstV3 = {1.0,1.0,1.0};
- printf("%f\n",vectDotProduct(tstV1,tstV2));
- printf("%f\n",vectDotProduct(tstV1,tstV3));
- printf("%f\n",vectDotProduct(tstV2,tstV3));
- printf("\n");
- return 0;
- }
- /*
- output:
- 0.000000
- 1.000000
- 2.000000
- */
Advertisement
Add Comment
Please, Sign In to add comment