-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathVector.java
executable file
·70 lines (59 loc) · 1.07 KB
/
Vector.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
/**
* Sachin Shah
* version 1
*/
public class Vector
{
public double a;
public double b;
public double c;
public double d;
public Vector(double a, double b)
{
this.a = a;
this.b = b;
this.c = 0;
this.d = 0;
}
public Vector(double a, double b, double c)
{
this.a = a;
this.b = b;
this.c = c;
this.d = 0;
}
public Vector(double a, double b, double c, double d)
{
this.a = a;
this.b = b;
this.c = c;
this.d = d;
}
public void set(Vector v)
{
this.a = v.a;
this.b = v.b;
this.c = v.c;
this.d = v.d;
}
public Vector plus(Vector v){
return new Vector(v.a+this.a, v.b+this.b, v.c+this.c);
}
public void add(Vector v){
this.a += v.a;
this.b += v.b;
this.c += v.c;
}
public double dot(Vector v){
return (this.a*v.a + this.b*v.b + this.c*v.c);
}
public Vector times(double s){
return new Vector(s*this.a, s*this.b, s*this.c);
}
public String toString(){
return String.format("(%f, %f, %f, %f)", a, b, c, d);
}
public boolean equals(Vector v){
return (v.a == this.a && v.b == this.b && v.c == this.c && v.d == this.d);
}
}