-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathanglebetweenvectors.java
More file actions
37 lines (23 loc) · 1.04 KB
/
anglebetweenvectors.java
File metadata and controls
37 lines (23 loc) · 1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
//This is a Java program for finding the angle between two vectors written in x,y form and classifying them as parallel, orthogonal(perpendicular), or neither
import java.lang.Math;
public class anglebetweenvectors {
static String b="";
public static void main(String[] args) {
double[][] c = {{2,1},{-1,2}};
System.out.println(anglebetweenvectorscalc(c));
}
private static String anglebetweenvectorscalc(double[][] a){
double f = (((a[0][0] * a[1][0]) + (a[0][1] * a[1][1])) / (Math.sqrt(((a[0][0]*a[0][0])+(a[0][1]*a[0][1]))*((a[1][0]*a[1][0])+(a[1][1]*a[1][1])))));
double g = Math.toDegrees(Math.acos(f));
if(g==180 || g==0){
b="parallel";
}
else if (g==90){
b = "orthoganal";
}
else {
b = "not orthagonal or parallel";
}
return "The angle between the two vectors is" +g+" so these two vectors are " + b + " to each other";
}
}