There is a body on the form, at the touch of a button it falls. There is an algorithm by which it falls on the surface for a certain time (depends on the height). How can one make the body motion uniformly accelerated and not at a constant speed like now?

procedure TMainForm.StartClick(Sender: TObject); const g = 9.81; var t,h:Double; begin h:=sSpinEdit1.Value; if (h<>0) then begin t:=Sqrt((2*h)/g)*1000;//вычисление времени timePX:= (h*8)/(t/10);//количество пикселей в 10мс end; if (>=MainForm.img1.Height-42)//проверка лежит ли на земле then else tmr1.Enabled:=True; MainForm.sSpinEdit1.Enabled:=False; end; procedure TMainForm.tmr1Timer(Sender: TObject); begin fc:=fc+Frac(timePX);//складывание остатков от timePX :=;//Прибавление целой части timePX if(fc>=1)//Прибавление остатка от timePX then begin :=; fc:=fc-1; end; if (>=MainForm.img1.Height-42) then tmr1.Enabled:=False; end; 

    2 answers 2

    Everything is quite simple, you need to calculate the acceleration of the object, it can be calculated using a simple formula: acceleration = distance / (time * time), based on this, the formula of movement will be

     accel:=len/(time*time); //считать до начала движения speed:=speed+accel; // считать каждую еденицу времени pos:=pos+speed; //считать каждую еденицу времени 

    Total will come out that the body moving equiporely will pass len distances in time.

      Now you probably have


      And you can do so:

       k:=k+0.1; Top:=Top+k; 

      That is, with each iteration the coefficient will grow linearly.

      • Everything is more complicated there. First, the time for which it should fall is calculated, based on this time and height, it is calculated how many pixels it should travel every 10ms. How to make it accelerate but the time of the fall remains the same? - Stope 5:26
      • Or show your code or call telepaths. although the acceleration will still be using the changing coefficient - vdk company
      • added code - Stope