私は模擬しようとしています投げ槍はアンドロイドです。ジャベリン軌道のあらゆる点で接線の傾きを計算します。すべての窓の弾道ポイントで接線の勾配のシミュレーションを投げて投げてください
y = Math.tan(radians) * x - g/(2 * Math.pow(v0, 2) * Math.pow(Math.cos(radians), 2)) * x^2
dy = Math.tan(radians) - (g * x)/(Math.pow(v0, 2) * Math.pow(Math.cos(radians), 2))
:軌道を計算することは、私は、Xに関してこの式を誘導体化ジャベリン軌跡の接線の傾きを算出する
x = (int) (x0 + v0 * t * Math.cos(radians)); //for coordinate x
と
y = (int) (y0 - v0 * t * Math.sin(radians) + 0.5 * g * t * t);
を発射運動方程式使用してい座標
問題は、仰角0-で約60度より正しく動作するということです。 仰角が大きい場合、正しい勾配を計算しません。
public class ThrowJavelin extends ImageView {
private Context mContext;
int x0 = -1;
int y0 = -1;
int x = x0;
int y = y0;
private Handler h;
private final int FRAME_RATE = 5;
private double t = 0;
private float g = 9.81f;
//initial velocity
private int v0;
//elevation angle in radians
private double radians;
//javelin current angle in degrees
private double javelin_angle;
public ThrowJavelin(Context context, AttributeSet attr) { super(context, attr); }
public ThrowJavelin(Context context, AttributeSet attrs, int defStyleAttr){ super(context, attrs, defStyleAttr); }
public ThrowJavelin(Context context, Bundle args) {
super(context);
mContext = context;
h = new Handler();
//input values
v0 = args.getInt("velocity");
radians = args.getDouble("radians");
}
private Runnable r = new Runnable() {
@Override
public void run() {
invalidate();
}
};
protected void onDraw(Canvas c) {
Bitmap javelin = BitmapFactory.decodeResource(getResources(), R.drawable.jav);
DerivativeStructure alpha = null;
if (x < 0 && y < 0) {
x0 = 0;
y0 = c.getHeight() - 200;
x = x0;
y = y0;
javelin = rotateBitmap(javelin, (float) Math.toDegrees(radians));
} else if (y > y0) { //reset to beginning
x = x0;
y = y0;
t = 0;
javelin = rotateBitmap(javelin, (float) Math.toDegrees(radians));
} else {
//calculate current coordinates (depends on t)
x = (int) (x0 + v0 * t * Math.cos(radians));
y = (int) (y0 - v0 * t * Math.sin(radians) + 0.5 * g * t * t);
if (x == 0) {
javelin_angle = Math.toDegrees(radians);
} else {
// dy of 3rd equation
javelin_angle = Math.toDegrees(Math.tan(radians) - (g * x)/(Math.pow(v0, 2) * Math.pow(Math.cos(radians), 2)));
}
javelin = rotateBitmap(javelin, javelin_angle);
t += 0.3;
}
c.drawBitmap(javelin, x, y, null);
h.postDelayed(r, FRAME_RATE);
}
public Bitmap rotateBitmap(Bitmap image, double angle){
float alpha = (float) angle;
Matrix mat = new Matrix();
System.out.println(-alpha);
mat.postRotate(-alpha);
return Bitmap.createBitmap(image, 0, 0, image.getWidth(), image.getHeight(), mat, true);
}
}
私は本当に理解していない、より大きな角度で正しく動作しない理由OT:ここ
はコードです。どんなアイデアですか?
この第二の方程式がすることになって何あれ? 't 'に対する' y'の導関数は 'dy = g * t - v0 * Math.sin(ラジアン)'です。結果の角度は 'tan(dy)'です。 –
@NicoSchertlerこんにちはニコ、2番目の方程式は、時間tに関してy座標を計算することになっています。私が必要とするのは、座標xに対する私のジャベリンの軌道を表す第3の方程式の逆数を計算することです。ところで、なぜ私が直接 'javelin_angle = Math.toDegrees(Math.tan(ラジアン) - (g * x)/(Math.pow(v0、2)* Math.pow(v0、2)*)を使うことができるときにDerivativeStructureを使用しているのかわかりません。 pow(Math.cos(ラジアン)、2)));しかし、状況は同じで、仰角が65度未満の間だけすべて正常に動作します – naco