From 3a663776e10700ca37e158de8ed580ecbfda0088 Mon Sep 17 00:00:00 2001 From: Brijeshcr Date: Tue, 11 Jul 2017 20:08:54 +0530 Subject: Cross Added --- src/c/matrixOperations/cross/u16crossa.c | 34 ++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 src/c/matrixOperations/cross/u16crossa.c (limited to 'src/c/matrixOperations/cross/u16crossa.c') diff --git a/src/c/matrixOperations/cross/u16crossa.c b/src/c/matrixOperations/cross/u16crossa.c new file mode 100644 index 0000000..e0a32bc --- /dev/null +++ b/src/c/matrixOperations/cross/u16crossa.c @@ -0,0 +1,34 @@ +#include +#include +#include +#include "uint16.h" + +void u16crossa (uint16* inp1, int size1_r, int size1_c, uint16* inp2, int size2_r, int size2_c ,uint16* oup) +{ + int i,j; + + if (size1_c == 3 && size1_r == 1) // Calculating the cross product for a 1X3 Matrix + { + oup[0] = inp1[1]*inp2[2] - inp1[2]*inp2[1]; + oup[1] = inp1[2]*inp2[0] - inp1[0]*inp2[2]; + oup[2] = inp1[0]*inp2[1] - inp1[1]*inp2[0]; + printf("%lf ", oup[0]); + printf("%lf ", oup[1]); + printf("%lf \n", oup[2]); + } + else // Calculating the cross product for a 3XN Matrix + { + for(i = 0; i < size1_r; i++) + { + for(j = 0; j < size1_c; j = j+3) + { + oup[j+(i*size1_r)] = inp1[(j+1)+(i*size1_r)] * inp2[(j+2)+(i*size1_r)] - inp1[(j+2)+(i*size1_r)] * inp2[(j+1)+(i*size1_r)]; + oup[(j+1)+(i*size1_r)] = inp1[(j+2)+(i*size1_r)] * inp2[(j+0)+(i*size1_r)] - inp1[(j+0)+(i*size1_r)] * inp2[(j+2)+(i*size1_r)]; + oup[(j+2)+(i*size1_r)] = inp1[(j+0)+(i*size1_r)] * inp2[(j+1)+(i*size1_r)] - inp1[(j+1)+(i*size1_r)] * inp2[(j+0)+(i*size1_r)]; + + } + } + + } +} + -- cgit