-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathVector.java
More file actions
45 lines (37 loc) · 833 Bytes
/
Vector.java
File metadata and controls
45 lines (37 loc) · 833 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
34
35
36
37
38
39
40
41
42
43
44
45
class Vector {
double a,b;
double c,d;
double beta;
public Vector(double x1, double y1, double x2, double y2) {
a = x1;
b = y1;
c = x2-x1;
d = y2-y1;
}
public Pair intersection(Vector o) {
Pair ret = new Pair(0,0);
//x
double xconst = o.a - a;
double xmybeta = c;
double xobeta = -1*o.c;
//y
double yconst = o.b - b;
double ymybeta = d;
double yobeta = -1*o.d;
double top = xconst * yobeta - yconst * xobeta;
double bot = xmybeta * yobeta - xobeta * ymybeta;
double div = top / bot;
ret = new Pair(a + (div*c), b + (div*d));
return ret;
}
public String toString() {
return "Vector (a b c d) = " + a + " " + b + " " + c + " " + d;
}
}
class Pair {
double x, y;
public Pair(double x, double y) {
this.x = x;
this.y = y;
}
}