Я задавал этот вопрос раньше, но мне кажется, что я плохо сформулировал его, и поэтому не получил никакого ответа.Я пытаюсь сделать приложение для Android, которое рисует путь объекта в движении снаряда.У меня есть уравнения для этой работы, но по какой-то причине, когда я запускаю свою программу, все, что я получаю, - это 2 соединенные линии вместо правильной дуги.Я часами смотрю на это, может кто-нибудь сказать мне, что происходит и что мне нужно сделать, чтобы это исправить?Вот мой код: (Он также рисует землю, но эта часть, кажется, работает. Она включена, потому что некоторые из переменных, используемых для создания земли, также используются в дуге.)
float constx = 400;
float consty = 375;
float deltx = (float) ProjectileMotionDrawingActivity.dx;
float delty = (float) ProjectileMotionDrawingActivity.dy;
float maxDrawingHeight;
float totwidth;
float totheight;
float starty;
float ydist;
float cx = canvas.getWidth()/2;
float cy = 210;
boolean limiter;
float vin = (float) ProjectileMotionDrawingActivity.vin;
float vxd = (float) ProjectileMotionDrawingActivity.vxd;
float acc = (float) ProjectileMotionDrawingActivity.ac;
float scaleda;
float scaledv;
float scaledvi;
//Set background color and get paint ready
canvas.drawColor(Color.WHITE);
Paint linePaint = new Paint(Paint.ANTI_ALIAS_FLAG);
linePaint.setColor(Color.BLACK);
//Define maxDrawingHeight
if(delty >= 0){
maxDrawingHeight = (float) ProjectileMotionDrawingActivity.mhe;
}else{
maxDrawingHeight = (float) (ProjectileMotionDrawingActivity.mhe + Math.abs(delty));
}
// Determine whether x or y is limiting factor (true=x, false =y) (For future use if needed)
if(Math.abs(maxDrawingHeight/deltx) >=consty/constx){
limiter = false;
}else{
limiter = true;
}
//set width and height of projectile motion
if(limiter){
totwidth = constx;
totheight = constx*maxDrawingHeight/deltx;
scaleda = acc*constx/deltx;
scaledvi = vin*constx/deltx;
scaledv = vxd*constx/deltx;
}else{
totheight = consty;
totwidth = consty*deltx/maxDrawingHeight;
scaleda = acc*consty/maxDrawingHeight;
scaledvi = vin*consty/maxDrawingHeight;
scaledv = vxd*consty/maxDrawingHeight;
}
//height of cliff
ydist = delty*totheight/maxDrawingHeight;
//start height
starty = cy+(totheight/2);
canvas.drawLine(0, starty, totwidth+35, starty, linePaint);
canvas.drawLine(totwidth+35, starty, totwidth+35, starty-ydist, linePaint);
canvas.drawLine(totwidth+35, starty-ydist, 2*cx, starty-ydist, linePaint);
//Parabola
float porabx = 35;
float poraby = starty;
float porabx2 = 35 + totwidth/50;
float poraby2 = (float) (starty - scaledvi*porabx2/scaledv-.5*scaleda*Math.pow(porabx2/scaledv,2));
for(int i=0;i<50;i++){
canvas.drawLine(porabx, poraby, porabx2, poraby2 , linePaint);
porabx = porabx2;
poraby = poraby2;
porabx2 += totwidth/50;
poraby2 = (float) (starty - scaledvi*porabx2/scaledv-.5*scaleda*Math.pow(porabx2/scaledv,2));
}
}
Обновление: Посмотрев на это некоторое время и попробовав разные числа, я считаю, что первая нарисованная линия - это правильная первая (1/50) дуга.По какой-то причине кажется, что есть проблема с переменной poraby2 в цикле.