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;
- void printVector(Vector3 v)
- {
- printf("%f %f %f\n", v.x, v.y, v.z);
- }
- Vector3 vectCrossProduct(Vector3 a, Vector3 b)
- {
- Vector3 retV = { a.y * b.z - a.z * b.y, a.z * b.x - a.x * b.z, a.x * b.y - a.y * b.x };
- return retV;
- }
- int main (int argc, char **argv)
- {
- Vector3 tstV1 = {1.0,0.0,0.0};
- Vector3 tstV2 = {0.0,1.0,0.0};
- Vector3 tstV3 = {1.0,1.0,1.0};
- printVector(vectCrossProduct(tstV1,tstV2));
- printVector(vectCrossProduct(tstV1,tstV3));
- printVector(vectCrossProduct(tstV2,tstV3));
- printf("\n");
- return 0;
- }
- /*
- output:
- 0.000000 0.000000 1.000000
- 0.000000 -1.000000 1.000000
- 1.000000 0.000000 -1.000000
- */
Advertisement
Add Comment
Please, Sign In to add comment