Commit 1056f1f2 by matjul

Upload New File

parent 0fedfb4d
Showing with 57 additions and 0 deletions
#include <math.h>
#include <stdio.h>
float vectorMagnitude(int vector[3]);
int dotProduct(int vector1[3], int vector2[3]);
float cosCompare(int vector1[3], int vector2[3]);
int main (){
int i,j;
int matrix[4][3] = {
{1, 4, 6},
{2, -3, 1},
{3, 5, 0},
{3, 1, -3}
};
for(i = 0; i < 4; i++){
for(j = 0; j < i; j++){
printf("%f\n", acos(cosCompare(matrix[i], matrix[j])));
}
}
return 0;
}
float vectorMagnitude(int vector[3]){
int sumOfSquares = 0;
for(int i = 0; i < 3; i++){
sumOfSquares += vector[i] * vector[i];
}
float magnitude = sqrt(sumOfSquares);
return magnitude;
}
int dotProduct(int vector1[3], int vector2[3]){
int dot = 0;
for(int i = 0; i < 3; i++){
dot += vector1[i] * vector2[i];
}
return dot;
}
float cosCompare(int vector1[3], int vector2[3]){
int dot = dotProduct(vector1, vector2);
float mag1 = vectorMagnitude(vector1);
float mag2 = vectorMagnitude(vector2);
float cosine = dot / (mag1 * mag2);
return cosine;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment