-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvector.java
More file actions
56 lines (54 loc) · 1.55 KB
/
Copy pathvector.java
File metadata and controls
56 lines (54 loc) · 1.55 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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
public class vector{
public double x, y;
vector()
{
x = 0;
y = 0;
}
vector(double x, double y)
{
this.x = x;
this.y = y;
}
vector(point p1)
{
this.x = p1.x;
this.y = p1.y;
}
public void add(vector v1)
{
x += v1.x;
y += v1.y;
}
public void calcVelocity(vector initialVelocity, vector acceleration, double seconds)
{
this.x = initialVelocity.x + acceleration.x * seconds;
this.y = initialVelocity.y + acceleration.y * seconds;
}
public static vector calcDistance(vector initialVelocity, vector acceleration, double seconds)
{
vector v1 = new vector();
v1.x = initialVelocity.x * seconds + acceleration.x * seconds * seconds / 2;
v1.y = initialVelocity.y * seconds + acceleration.y * seconds * seconds / 2;
return v1;
}
public static vector calcDistance(vector initialVelocity, double seconds)
{
vector deltaDistance = new vector();
deltaDistance.x = initialVelocity.x * seconds;
deltaDistance.y = initialVelocity.y * seconds;
return deltaDistance;
}
public void setVector(double x, double y)
{
this.x = x;
this.y = y;
}
public vector rotateBy(double angle)
{
vector tmp = new vector();
tmp.x = Math.cos(angle) * this.x - Math.sin(angle) * this.y;
tmp.y = Math.sin(angle) * this.x + Math.cos(angle) * this.y;
return tmp;
}
}