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.shp1.top>=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 MainForm.shp1.top := MainForm.shp1.top+Trunc(timePX);//ΠŸΡ€ΠΈΠ±Π°Π²Π»Π΅Π½ΠΈΠ΅ Ρ†Π΅Π»ΠΎΠΉ части timePX if(fc>=1)//ΠŸΡ€ΠΈΠ±Π°Π²Π»Π΅Π½ΠΈΠ΅ остатка ΠΎΡ‚ timePX then begin MainForm.shp1.top := MainForm.shp1.top+Trunc(fc); fc:=fc-1; end; if (MainForm.shp1.top>=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

      Top:=Top+1

      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