-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSkater.java
More file actions
242 lines (200 loc) · 5.42 KB
/
Skater.java
File metadata and controls
242 lines (200 loc) · 5.42 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
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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
import java.lang.Math;
import java.util.*;
import java.awt.*;
import javax.swing.*;
import java.awt.Rectangle;
public class Skater{
private double mass;
private double height;
private double gravity;
private double coeff;
private double dist;
private double totalE;
private double kineticE;
private double potentialE;
private double thermalE;
private double angle;
private double px,py;
private Vector<Double> position = new Vector<Double>(2);
private Vector<Double> velocity = new Vector<Double>(2);
private Rectangle location;
private Color color = new Color(200,0,0);
public Skater(){
mass = 50.0;
gravity = 9.81;
coeff = 0;
reset();
}
public void reset() {
position.add(45.0);
position.add(-1 * (320.0/62500)*Math.pow(45.0 - 290,2)+500);
px = 100;
py = 510;
setHeight();
dist = 0;
setTotEnergy();
position.clear();
position.add(45.1);
position.add(-1 * (320.0/62500)*Math.pow(45.1 - 290,2)+500);
velocity.add(0.0);
velocity.add(0.0);
Vector<Double> temp = new Vector<Double>(2);
temp.clear();
temp.add(45.0);
temp.add(-1 * (320.0/62500)*Math.pow(45.0 - 290,2)+500);
setDist(temp);
setAngle(temp);
setHeight();
setPotEnergy();
thermalE = 0;
setKinEnergy();
setVelocity();
setVelocity();
double vel = Math.sqrt((2 * this.kineticE)/this.mass);
velocity.add(Math.cos(angle) * vel);
velocity.add(Math.sin(angle) * vel);
location = new Rectangle((int)(90), (int)(500), (int)(20),(int)( 20));
}
public void setMotion(double newX, double newY){
position.set(0,newX);
position.set(1,newY);
}
public double getMass(){
return this.mass;
}
public void setMass(double m) {
this.mass = m;
}
public double geHeight() {
return this.height;
}
public void setHeight() {
double ans = (500 - position.get(1))*10;
this.height = ans;
}
public double getGravity(){
return this.gravity;
}
public void setGravity(double g) {
this.gravity = g;
}
public double getCoeff(){
return this.coeff;
}
public void setCoeff(double c) {
this.coeff = c;
}
public double getDist() {
return this.dist;
}
public double setDist(Vector<Double> old) {
double ans = Math.sqrt(Math.pow(old.get(0)-this.position.get(0),2)+Math.pow(old.get(1)-this.position.get(1),2));
dist += ans/80;
return ans;
}
public double getAngle() {
return this.angle;
}
public void setAngle(Vector<Double> old) {
double ans;
if ((old.get(0) - this.position.get(0)) <= 0 && (old.get(1) - this.position.get(1)) <= 0) {
ans = 2*Math.PI - Math.atan((old.get(1)-this.position.get(1))/(old.get(0)-this.position.get(0)));
this.angle = ans;
}
if ((old.get(0) - this.position.get(0)) <= 0 && (old.get(1) - this.position.get(1)) > 0) {
ans = Math.atan((-1 * (old.get(1)-this.position.get(1))/(old.get(0)-this.position.get(0))));
this.angle = ans;
}
if ((old.get(0) - this.position.get(0)) > 0 && (old.get(1) - this.position.get(1)) <= 0) {
ans = Math.PI - Math.atan((old.get(1)-this.position.get(1))/(old.get(0)-this.position.get(0)));
this.angle = ans;
}
if ((old.get(0) - this.position.get(0)) > 0 && (old.get(1) - this.position.get(1)) > 0) {
ans = Math.PI + Math.atan((-1 * (old.get(1)-this.position.get(1))/(old.get(0)-this.position.get(0))));
this.angle = ans;
}
}
public double getPosX(){
return this.position.get(0);
}
public double getPosY(){
return this.position.get(1);
}
public void setPosition(double x, double y){
this.position.set(0,x);
this.position.set(1,y);
}
public double getVelX(){
return this.velocity.get(0);
}
public void setVelX(double v){
this.velocity.set(0,v);
}
public double getVelY(){
return this.velocity.get(1);
}
public int radius(){
return location.width/2;
}
public int x(){
return location.x + radius();
}
public int y(){
return location.y + radius();
}
public double xMotion(){
return px;
}
public double yMotion(){
return py;
}
public Rectangle region(){
return location;
}
public double getVelocity(){
double velocity = Math.sqrt(Math.pow(this.velocity.get(0),2)+Math.pow(this.velocity.get(1),2));
return velocity;
}
public void setVelocity() {
double vel = Math.sqrt((this.kineticE)/this.mass);
this.velocity.set(0,Math.cos(angle) * vel);
this.velocity.set(1,-1 * Math.sin(angle) * vel);
}
public double getPotEnergy() {
return this.potentialE;
}
public void setPotEnergy() {
double ans = mass * gravity * height;
this.potentialE = ans;
}
public double getTotEnergy() {
return this.totalE;
}
public void setTotEnergy() {
double ans = mass * gravity * 3350;
this.totalE = ans;
}
public double getThermEnergy() {
return this.thermalE;
}
public void setThermEnergy() {
double ans = coeff * mass * gravity * Math.abs(Math.cos(angle)) * dist/500;
this.thermalE += ans;
}
public double getKinEnergy() {
return this.kineticE;
}
public void setKinEnergy() {
double ans = this.totalE - this.potentialE - this.thermalE;
this.kineticE = ans;
}
public void moveTo(double x, double y){
location.setLocation((int)x, (int) y);
}
public void move(){
location.translate((int) px,(int) py);
}
public void paint(Graphics g){
g.fillOval(location.x, location.y, location.width,location.height);
}
}