-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOperations.java
More file actions
33 lines (29 loc) · 849 Bytes
/
Operations.java
File metadata and controls
33 lines (29 loc) · 849 Bytes
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
import java.lang.Math;
public class Operations extends Vector
{
public Operations(int xI, int yI){
super(xI, yI);
}
public int dot(Vector a)
{
return (super.x * a.x) + (super.y * a.y);
}
public double magnitude(){
double len = Math.sqrt( Math.pow(super.x, 2) + Math.pow(super.y, 2) );
super.display();
return len;
}
public double[] convertToPolar(){
double theta = Math.atan(super.y/super.x) * (180.0/Math.PI);
double radius = Math.sqrt( Math.pow(super.x,2) + Math.pow(super.y, 2) );
if(super.x > 0){
if(super.y < 0){
theta = theta + 360;
}
} else {
theta = theta + 180;
}
double[] polar = {radius,theta};
return polar;
}
}