Rzut ukośny - Pascal
Friday, 9. November 2007, 14:10:43
Program Rzut_Ukosny;
(* ######################################## *)
(* # # *)
(* # Program rysuje wykres rzutu ukosnego # *)
(* # z dana sila i katem rzutu # *)
(* # # *)
(* ######################################## *)
Uses
Crt, Graph;
Function RealToStr(E: Real): String;
Var
S: String[11];
Begin
Str(E:8:2, S);
While s[1] = ' ' Do
Delete(S,1,1);
RealToStr := S;
End;
Function ZaokrSkale(Wysokosc: Real): Integer;
Var
J : Integer;
Begin
J := 1;
While Wysokosc > 10 Do
Begin
J := J * 10;
Wysokosc := Wysokosc / 10;
End;
ZaokrSkale := Round(Wysokosc + 0.5) * J;
End;
Const
G : Real = 9.81;(* Przyspieszenie ziemskie *)
WWidth : Integer = 605;(* Szerokosc wykresu *)
WHeight : Integer = 435;(* Wysokosc wykresu *)
Var
V0 : Real;(* Predkosc poczatkowa *)
Alfa : Real;(* Kat rzutu *)
Vx, Vy : Real;(* Skladowe wektora rzutu *)
HMax : Real;(* Maksymalna osiagnieta wysokosc *)
Z : Real;(* Zasieg rzutu *)
Tc : Real; (* Calkowity czas lotu *)
T : Integer;(* Czas *)
I : Integer; (* Zmienna do petli *)
X, X2, Y, Y2 : Integer;
Drv, Trb : Integer; (* Do obslugi grafiki *)
Begin
ClrScr;
WriteLn('## Program rysuje wykres rzutu ukosnego ##');
(* Wstawianie wartosci *)
Repeat
Begin
Write('Podaj predkosc poczatkowa (Vo) rzutu: ');
ReadLn(V0);
Write('Podaj kat (Alfa) rzutu w stopniach: ');
ReadLn(Alfa);
WriteLn;
If V0 <= 0 Then
WriteLn('!! Warotsc predkosci poczatkowej musi byc wieksza od 0 !!');
If Alfa <= 0 Then
WriteLn('!! Kat rzutu musi byc wiekszy od 0 !!');
WriteLn;
End
Until (V0 > 0) And (Alfa > 0);
(* Obliczanie danych *)
Alfa := (Alfa * pi) / 180; (* !! Zamiana kata na radiany !! *)
Vx := V0 * Cos(Alfa);
Vy := V0 * Sin(Alfa);
Tc := (2 * V0 * Sin(Alfa)) / G;
HMax := (Sqr((V0 * Sin(Alfa)))) / (2 * G);
Z := Vx * Tc;
(* Rysowanie wykresu *)
ClrScr;
Drv := VGA;
Trb := VGAHi;
InitGraph(Drv, Trb, 'C:\TP\BGI');
SetColor(DarkGray);
Line(15,10,15,475);
Line(5,465,630,465);
Line(10,15,15,10);
Line(20,15,15,10);
Line(625,460,630,465);
Line(625,470,630,465);
SetColor(LightGray);
OutTextXY(21,10,'y');
OutTextXY(620,449,'x');
SetColor(DarkGray);
For I := 0 To 20 Do
Begin
Line(13, 465 - Round(I*WHeight/20), 17, 465 - Round(I*WHeight/20));
Line(15 + Round(I*WWidth/20), 463, 15 + Round(I*WWidth/20), 467);
End;
SetColor(LightGray);
For I := 0 to 20 do
If (I > 0) and ((I Div 2) * 2 = I) Then
Begin
OutTextXY(21, 465 - Round(I*WHeight/20) - 3, RealToStr((I*ZaokrSkale(HMax))/20));
OutTextXY(15 + Round(I*WWidth/20)-20, 469, RealToStr((I*ZaokrSkale(Z))/20));
End;
SetColor(DarkGray);
Line(15 + Round(((Z*WWidth)/ZaokrSkale(Z))/2),
465-Round((HMax*WHeight)/ZaokrSkale(HMax)), 15 + Round(((Z*WWidth)/ZaokrSkale(Z))/2),465);
SetColor(Green);
X := 15;
Y := 465;
For T := 0 To WWidth Do
Begin
X2 := 15 + Round((V0 * Cos(Alfa) * T * Tc / WWidth) * WWidth / ZaokrSkale(Z));
Y2 := 465 - Round(((V0 * Sin(Alfa) * T * Tc / WWidth) - (G * Sqr(T * Tc / WWidth)) / 2) * WHeight / ZaokrSkale(HMax));
Line(X,Y,X2,Y2);
X := X2;
Y := Y2;
End;
SetColor(LightGray);
OutTextXY(18 + Round(((Z*WWidth)/ZaokrSkale(Z))/2), 465-Round(((HMax*WHeight)/ZaokrSkale(HMax))/2), 'h max');
SetColor(Green);
OutTextXY(400, 15, 'Maksymalna wysokosc: ' + RealToStr(HMax));
OutTextXY(400, 35, 'Przebyta droga: ' + RealToStr(Z));
OutTextXY(400, 55, 'Czas trwania rzutu: ' + RealToStr(Tc) + 's');
readln;
End.