Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const
- init_force = 100; // Initial acceleration - ms^-2 (same as force in newtons assuming 1 kg projectile)
- init_angle = 30; // Initial angle in degrees, with horizontal being 0 and vertical being 90
- grav = 9.81; // Gravity, x ms^-2
- res = 1; // Resistance, x ms^-2
- var
- 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
- i: Integer; // Timer
- arc: TPointArray;
- tb: TBox;
- begin
- r_for := init_force;
- x_pos := 0;
- y_pos := 0;
- cur_ang := Radians(init_angle);
- i := 0;
- repeat
- SetLength(arc, i + 1);
- arc[i] := Point(Round(x_pos), Round(y_pos));
- r_for := r_for - res;
- x_for := r_for * Cos(cur_ang);
- x_pos := x_pos + x_for;
- y_for := (r_for * Sin(cur_ang)) - grav;
- y_pos := y_pos + y_for;
- if (y_pos < 0) then
- y_pos := 0;
- cur_ang := ArcTan(y_for / x_for);
- r_for := x_for / Cos(cur_ang);
- i := i + 1;
- until y_pos = 0;
- SetLength(arc, i + 1);
- arc[i] := Point(Round(x_pos), Round(y_pos));
- tb := GetTPABounds(arc);
- tb.y2 := tb.y2 + 5;
- DisplayDebugImgWindow(tb.x2, tb.y2 + 5);
- Wait(50);
- GetDebugCanvas.Brush.Color := clWhite;
- GetDebugCanvas.Rectangle(0, 0, tb.x2, tb.y2 + 5);
- GetDebugCanvas.MoveTo(0, tb.x2);
- GetDebugCanvas.Pen.Color := clBlack;
- for i := 0 to High(arc) do
- GetDebugCanvas.LineTo(arc[i].x, tb.y2 - arc[i].y);
- end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement