Advertisement
mixster

mixster

Oct 4th, 2009
214
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 1.45 KB | None | 0 0
  1. const
  2.   init_force = 100; // Initial acceleration - ms^-2 (same as force in newtons assuming 1 kg projectile)
  3.   init_angle = 30; // Initial angle in degrees, with horizontal being 0 and vertical being 90
  4.   grav = 9.81; // Gravity, x ms^-2
  5.   res = 1; // Resistance, x ms^-2
  6.  
  7. var
  8.   r_for, x_for, y_for, cur_ang, x_pos, y_pos: Extended; // resultant force; x and y components of resultant force; current angle of projectile
  9.   i: Integer; // Timer
  10.   arc: TPointArray;
  11.   tb: TBox;
  12.  
  13. begin
  14.   r_for := init_force;
  15.   x_pos := 0;
  16.   y_pos := 0;
  17.   cur_ang := Radians(init_angle);
  18.   i := 0;
  19.   repeat
  20.     SetLength(arc, i + 1);
  21.     arc[i] := Point(Round(x_pos), Round(y_pos));
  22.    
  23.     r_for := r_for - res;
  24.     x_for := r_for * Cos(cur_ang);
  25.     x_pos := x_pos + x_for;
  26.    
  27.     y_for := (r_for * Sin(cur_ang)) - grav;
  28.     y_pos := y_pos + y_for;
  29.     if (y_pos < 0) then
  30.       y_pos := 0;
  31.  
  32.     cur_ang := ArcTan(y_for / x_for);
  33.     r_for := x_for / Cos(cur_ang);
  34.    
  35.     i := i + 1;
  36.   until y_pos = 0;
  37.  
  38.   SetLength(arc, i + 1);
  39.   arc[i] := Point(Round(x_pos), Round(y_pos));
  40.   tb := GetTPABounds(arc);
  41.  
  42.   tb.y2 := tb.y2 + 5;
  43.  
  44.   DisplayDebugImgWindow(tb.x2, tb.y2 + 5);
  45.   Wait(50);
  46.   GetDebugCanvas.Brush.Color := clWhite;
  47.   GetDebugCanvas.Rectangle(0, 0, tb.x2, tb.y2 + 5);
  48.   GetDebugCanvas.MoveTo(0, tb.x2);
  49.   GetDebugCanvas.Pen.Color := clBlack;
  50.  
  51.   for i := 0 to High(arc) do
  52.     GetDebugCanvas.LineTo(arc[i].x, tb.y2 - arc[i].y);
  53. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement