Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
phkarl
/
IAX0583
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
7fa7d2ef
authored
Oct 08, 2018
by
phkarl
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Upload New File
parent
c47c04fd
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
69 additions
and
0 deletions
Lab6Classwork.c
Lab6Classwork.c
0 → 100644
View file @
7fa7d2ef
#include <stdio.h>
#include <math.h>
int
dotProduct
(
int
vector1
[
3
],
int
vector2
[
3
]);
double
vectorMagnitude
(
int
vector
[
3
]);
double
cosCompare
(
int
vector1
[
3
],
int
vector2
[
3
]);
double
angleInDegree
(
double
cosine
);
int
main
(){
int
matrix
[
4
][
3
]
=
{
{
1
,
4
,
6
},
{
2
,
-
3
,
1
},
{
3
,
5
,
0
},
{
3
,
1
,
-
3
}};
printf
(
"vector1 vector2 angle in degree
\n
"
);
for
(
int
i
=
0
;
i
<
4
;
i
=
i
+
2
){
for
(
int
j
=
0
;
j
<
4
;
j
++
){
if
(
j
!=
i
){
for
(
int
q
=
0
;
q
<
3
;
q
++
){
printf
(
"%d "
,
matrix
[
i
][
q
]);
}
printf
(
" "
);
for
(
int
p
=
0
;
p
<
3
;
p
++
){
printf
(
"%d "
,
matrix
[
j
][
p
]);
}
printf
(
" "
);
printf
(
"%lf
\n
"
,
angleInDegree
(
cosCompare
(
matrix
[
i
],
matrix
[
j
])));
}
}
}
return
0
;
}
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
;
}
double
vectorMagnitude
(
int
vector
[
3
]){
int
sumOfSquares
=
0
;
for
(
int
i
=
0
;
i
<
3
;
i
++
){
sumOfSquares
+=
vector
[
i
]
*
vector
[
i
];
}
double
magnitude
=
sqrt
(
sumOfSquares
);
return
magnitude
;
}
double
cosCompare
(
int
vector1
[
3
],
int
vector2
[
3
]){
int
dot
=
dotProduct
(
vector1
,
vector2
);
double
mag1
=
vectorMagnitude
(
vector1
);
double
mag2
=
vectorMagnitude
(
vector2
);
double
cosine
=
dot
/
(
mag1
*
mag2
);
return
cosine
;
}
double
angleInDegree
(
double
cosine
){
double
angle
;
angle
=
acos
(
cosine
);
angle
=
angle
*
(
180
.
0
/
3
.
14159265
);
return
angle
;
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment