大きな円の中に小さな円があります。小さな円が飛び交っていて、小さな円が大きな円の境界に来たら衝突するはずです。私はほとんどそうすることができましたが、それでも完全には機能しません。円が境界の直前で衝突することもあれば、境界の直後で衝突することもあります。これは私のコードです:
if (!(Math.pow((xSmallCircle + radiusSmallCircle) - (xBigCircle), 2) + Math.pow((
ySmallCircle + radiusSmallCircle) - yBigCircle, 2) < Math.pow(radiusBigCircle + 10, 2))) {
xVelocity *= -1;
yVelocity *= -1;
} else if (!(Math.pow((xSmallCircle - radiusSmallCircle) - (xBigCircle), 2) + Math.pow((
ySmallCircle - radiusSmallCircle) - yBigCircle, 2) < Math.pow(radiusBigCircle + 10, 2))) {
xVelocity *= -1;
yVelocity *= -1;
} else if (!(Math.pow((xSmallCircle + radiusSmallCircle) - (xBigCircle), 2) + Math.pow((
ySmallCircle - radiusSmallCircle) - yBigCircle, 2) < Math.pow(radiusBigCircle + 10, 2))) {
xVelocity *= -1;
yVelocity *= -1;
} else if (!(Math.pow((xSmallCircle - radiusSmallCircle) - (xBigCircle), 2) + Math.pow((
ySmallCircle + radiusSmallCircle) - yBigCircle, 2) < Math.pow(radiusBigCircle + 10, 2))) {
xVelocity *= -1;
yVelocity *= -1;
}
これが機能しない理由はありますか?