-
Notifications
You must be signed in to change notification settings - Fork 0
/
workspace.java
142 lines (112 loc) · 5.67 KB
/
workspace.java
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;
public class Workspace {
public static void main(String args[]) {
ArrayList<ArrayList<Integer>> equation = new ArrayList<ArrayList <Integer>>();
ArrayList<Integer> term1 = new ArrayList<Integer>(Arrays.asList(0, 1, 1));
equation.add(term1);
Equation equation1 = new Equation(equation);
System.out.println(equation1.equationAtPoint(1));
Scanner scanner = new Scanner(System.in);
System.out.println("Vector Calculator Operation: ");
String operation = scanner.nextLine();
Vector3D vector2 = new Vector3D(0, 0, 0);
Vector3D vector1 = new Vector3D(0, 0, 0);
Point3D point2 = new Point3D(0, 0, 0);
Point3D point1 = new Point3D(0, 0, 0);
if(operation.equals("generate vector")) {
System.out.println("Point 1");
point1 = pointInput(scanner);
System.out.println("Point 2");
point2 = pointInput(scanner);
} else {
System.out.println("Vector 1");
vector1 = vectorInput(scanner);
if(operation.equals("multiply by scalar") || !operation.equals("magnitude") || !operation.equals("cylindrical coordinates") || !operation.equals("spherical coordinates")) {
} else {
System.out.println("Vector 2");
vector2 = vectorInput(scanner);
}
}
System.out.println("Calculating ...");
switch (operation) {
case "add":
final Vector3D addition = vector1.add(vector2);
final String add = String.format("x: %f, y: %f, z: %f", addition.getX(), addition.getY(), addition.getZ());
System.out.println(add.toString()); // Displays result
break;
case "subtract":
final Vector3D subtraction = vector1.subtract(vector2);
final String sub = String.format("x: %f, y: %f, z: %f", subtraction.getX(), subtraction.getY(), subtraction.getZ());
System.out.println(sub.toString());
break;
case "multiply by scalar":
System.out.println("Scalar: ");
double scalar = scanner.nextDouble();
final Vector3D multiply = vector1.multiplyByScalar(scalar);
final String multi = String.format("x: %f, y: %f, z: %f", multiply.getX(), multiply.getY(), multiply.getZ());
System.out.println(multi.toString());
break;
case "dot product":
final double dotP = vector1.dotProduct(vector2);
final String dot = String.format("Dot Product Result: %f", dotP);
System.out.println(dot.toString());
break;
case "cross product":
final Vector3D crossP = vector1.crossProduct(vector2);
final String cross = String.format("x: %f, y: %f, z: %f", crossP.getX(), crossP.getY(), crossP.getZ());
System.out.println(cross.toString());
break;
case "magnitude":
final double magnitude = vector1.magnitude();
final String mag = String.format("Magnitude of Vector: %f", magnitude);
System.out.println(mag.toString());
break;
case "angle between":
final double angleBetween = vector1.angleBetween(vector2);
final String angle = String.format("Angle Between Vector One & Vector Two: %f", angleBetween);
System.out.println(angle.toString());
break;
case "cylindrical coordinates":
final Vector3D cylindrical = vector1.convertToCylindrical();
final String cyl = String.format("Cylindrical Coordinates of Vector One:\nx: %f, y: %f, z: %f", cylindrical.getX(), cylindrical.getY(), cylindrical.getZ());
System.out.println(cyl.toString());
break;
case "spherical coordinates":
final Vector3D spherical = vector1.convertToSpherical();
final String sphere = String.format("Cylindrical Coordinates of Vector One:\nx: %f, y: %f, z: %f", spherical.getX(), spherical.getY(), spherical.getZ());
System.out.println(sphere.toString());
break;
case "generate vector":
final Vector3D vectorP = point1.vectorBetweenPoints(point2);
final String vectorPoints = String.format("x: %f, y: %f, z: %f", vectorP.getX(), vectorP.getY(), vectorP.getZ());
System.out.println(vectorPoints.toString());
break;
default:
System.out.println("Input Valid Vector Operation");
}
}
public static Point3D pointInput(Scanner scanner){
Point3D point;
System.out.println("Enter Point X: ");
double xP = scanner.nextDouble();
System.out.println("Enter Point Y: ");
double yP = scanner.nextDouble();
System.out.println("Enter Point Z: ");
double zP = scanner.nextDouble();
point = new Point3D(xP, yP, zP);
return point;
}
public static Vector3D vectorInput(Scanner scanner) {
Vector3D vector;
System.out.println("Enter Vector X: ");
double xV = scanner.nextDouble();
System.out.println("Enter Vector Y: ");
double yV = scanner.nextDouble();
System.out.println("Enter vector Z: ");
double zV = scanner.nextDouble();
vector = new Vector3D(xV, yV, zV);
return vector;
}
}