Prueba
Embed:
(wiki syntax)
Show/hide line numbers
Vector.cpp
00001 // 00002 // Created by m007 on 03/04/2020. 00003 // 00004 #include "Vector.h" 00005 #include "Vector.h" 00006 void copyVector(struct Vector_3N* vector1, struct Vector_3N vector2){ 00007 for (int x=0;x<3;x++){ 00008 vector1->vector[x] = vector2.vector[x]; 00009 } 00010 } 00011 struct Vector_3N ProdMatrVect(float mat1[][3], float vector[3], float factor){ 00012 struct Vector_3N a; 00013 for (int x=0;x<3;x++){ 00014 a.vector[x]= (mat1[x][0]*vector[0]+mat1[x][1]*vector[1]+mat1[x][2]*vector[2])*factor; 00015 if( (a.vector [x]>-0.01)&&(a.vector [x])<0.01){ 00016 a.vector [x] = 0; 00017 } 00018 } 00019 return a; 00020 } 00021 struct Vector_4N ProdMatrVect_4N(float mat1[][4], float vector[4],float factor){ 00022 struct Vector_4N a; 00023 for (int x=0;x<4;x++){ 00024 a.vector[x]= (mat1[x][0]*vector[0]+mat1[x][1]*vector[1]+mat1[x][2]*vector[2])*factor; 00025 if( (a.vector [x]>-0.01)&&(a.vector [x])<0.01){ 00026 a.vector [x] = 0; 00027 } 00028 } 00029 return a; 00030 } 00031 struct Vector_3N ProdVectMatr(float vector[3],float mat1[][3],float factor){ 00032 struct Vector_3N a; 00033 for (int x=0;x<3;x++){ 00034 a.vector[x]= (mat1[0][x]*vector[0]+mat1[1][x]*vector[1]+mat1[2][x]*vector[2])*factor; 00035 if( (a.vector [x]>-0.01)&&(a.vector [x])<0.01){ 00036 a.vector [x] = 0; 00037 } 00038 } 00039 return a; 00040 } 00041 struct Vector_3N AddVectors(float v_A[3], float v_B[3]){ 00042 struct Vector_3N a; 00043 for(int x=0;x<3;x++) { 00044 a.vector[x] = v_A[x] + v_B[x]; 00045 } 00046 return a; 00047 } 00048 struct Vector_3N SubtractionVectors(float v_A[3], float v_B[3]){ 00049 struct Vector_3N a; 00050 for(int x=0;x<3;x++) { 00051 a.vector[x] = v_A[x] - v_B[x]; 00052 if( (a.vector [x]>-0.000001)&&(a.vector [x])<0.000001){ 00053 a.vector [x] = 0; 00054 } 00055 } 00056 return a; 00057 } 00058 float ProdVectors(float v_A[3], float v_B[3]){ 00059 float ans=0; 00060 for(int x=0;x<3;x++) { 00061 ans = ans+(v_A[x] * v_B[x]); 00062 } 00063 return ans; 00064 } 00065 struct Vector_3N crossProduct(float v_A[3], float v_B[3]) { 00066 struct Vector_3N a; 00067 a.vector[0] = v_A[1] * v_B[2] - v_A[2] * v_B[1]; 00068 a.vector[1] = -(v_A[0] * v_B[2] - v_A[2] * v_B[0]); 00069 a.vector[2] = v_A[0] * v_B[1] - v_A[1] * v_B[0]; 00070 for (int x=0; x<3; x++){ 00071 if( (a.vector [x]>-0.000001)&&(a.vector [x])<0.000001){ 00072 a.vector [x] = 0; 00073 } 00074 00075 } 00076 return a; 00077 } 00078 struct Vector_3N ProdVectConst(float v_A[3], float c){ 00079 struct Vector_3N a; 00080 for(int i=0; i<3; i++){ 00081 a.vector[i] = v_A[i] * c; 00082 } 00083 return a; 00084 } 00085 struct Vector_3N zeros(int max){ 00086 struct Vector_3N a; 00087 for(int i=0; i<max; i++){ 00088 a.vector[i] = 0; 00089 } 00090 return a; 00091 }
Generated on Thu Jul 28 2022 11:10:45 by
1.7.2