質問編集履歴
1
プログラムの修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -128,7 +128,7 @@
|
|
128
128
|
|
129
129
|
graphics.drawString("ボールの衝突回数:"+count+"回", 500, 300);
|
130
130
|
|
131
|
-
if((ball.getX()-ballEx.getX())*(ball.getX()-ballEx.getX())+(ball.getY()-ballEx.getY())*(ball.getY()-ballEx.getY())<=ball.getR()*ball.getR())
|
131
|
+
if((ball.getX()-ballEx.getX())*(ball.getX()-ballEx.getX())+(ball.getY()-ballEx.getY())*(ball.getY()-ballEx.getY())<=(double)2*ball.getR()*ball.getR())
|
132
132
|
|
133
133
|
count++;
|
134
134
|
|
@@ -154,13 +154,13 @@
|
|
154
154
|
|
155
155
|
}
|
156
156
|
|
157
|
-
if((ball.getX()-ballEx.getX())*(ball.getX()-ballEx.getX())+(ball.getY()-ballEx.getY())*(ball.getY()-ballEx.getY())<=ball.getR()*ball.getR()){
|
157
|
+
if((ball.getX()-ballEx.getX())*(ball.getX()-ballEx.getX())+(ball.getY()-ballEx.getY())*(ball.getY()-ballEx.getY())<=(double)2*ball.getR()*ball.getR()){
|
158
158
|
|
159
159
|
ball.setVx(((1+ball.getE())*ball.getVx()+(1-ball.getE())*ballEx.getVx())/(double)2);
|
160
160
|
|
161
161
|
ball.setVy(((1+ball.getE())*ball.getVy()+(1-ball.getE())*ballEx.getVy())/(double)2);
|
162
162
|
|
163
|
-
ballEx.setVx(((1-ball.getE())*ball.getVx()+(1+ball.getE())*ballEx.getVx())/(double)2);//2つのボールにおける中心間の距離が
|
163
|
+
ballEx.setVx(((1-ball.getE())*ball.getVx()+(1+ball.getE())*ballEx.getVx())/(double)2);//2つのボールにおける中心間の距離が直径より小さくなれば
|
164
164
|
|
165
165
|
ballEx.setVy(((1-ball.getE())*ball.getVy()+(1+ball.getE())*ballEx.getVy())/(double)2);//衝突したと判定として運動量保存則に基づき速度を変える
|
166
166
|
|