谁能向我解释为什么speed
计算关闭?
这是一个浮点计算。我在日志打印中显示(下)所有涉及的因素。
根据我的手算机:
长度:sqrt(3.497924^2 + (-1.134711)^2) = 3.67736881
速度:1.05 * 3.67736881 = 3.86123725
这与打印结果3.879624 相差 4.739 10^-3
编码:
float factor = yTouch(paddle, ballBounds);
float speed = SPEED_TRANSFER[level] * PointF.length(mSpeed.x, mSpeed.y);
double alpha = Math.PI/2;
double beta = Math.atan2(mSpeed.y, mSpeed.x);
double tau = -(2*alpha+beta);
Log.v("debug", String.format("speed(%f) mSpeed(%f,%f) transfer(%2.2f)
length(%f) Original tau(%3.2f)", speed, mSpeed.x, mSpeed.y,
SPEED_TRANSFER[level], PointF.length(mSpeed.x, mSpeed.y), tau/Math.PI));
日志:
03-24 10:48:53.421: V/debug(3236): speed(3.879624) mSpeed(3.497924,-1.134711) transfer(1.05) length(3.677369) Original tau(-0.90)
编辑
我试过了,直接乘法是对的。
Log.v("debug", "Direct multiplication:" + (1.05f * 3.677369f) );
03-24 11:49:08.687: V/debug(7644): Direct multiplication:3.8612373