-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtrajecto2.cpp
More file actions
executable file
·125 lines (119 loc) · 2.91 KB
/
Copy pathtrajecto2.cpp
File metadata and controls
executable file
·125 lines (119 loc) · 2.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
#include <ccbp.h>
#include <math.h>
#include <stdio.h>
#include <conio.h>
#define PR 0.001
#define MAX 1000
#define PI 3.14
void main ( )
{
int k1=1;
float x0,x1;
float a,b,c,g=9.88,k=0.7;
float j, i, l, x, y, t = 0.05, v, an;
int m=12, gd = DETECT, gm;
unsigned size;
void *pp;
initgraph ( &gd, &gm, "e:\\tc\\bgi" );
outhzxy3 ( 240, 70, "Trajectory", 2, 0, 14 );
outhzxy3 ( 50, 410, "Red line is the ideal trajectory, white line is the true trajectory.", 1, 0, 3 );
setfillstyle ( 1, 1 );
bar ( 0, 93, 640, 390 );
/* setfillstyle ( 1, 1 );
bar (480,400,595,450);
setcolor(15);
line(480,400,595,400); */
setcolor(5);
line(0,93,640,93);
line(0,390,640,390);
/* coordc ( 480, 450, 125, 0, 125, 15 );
coordc ( 500, 450, 62, 90, 62, 15 );
outhzxy3 ( 595, 450, " x ", 3, 0, 15 );
outhzxy3 ( 500, 381, " y ", 3, 0, 15 );
outhzxy3 ( 500, 450, " o ", 3, 0, 15 ); */
size=imagesize(0,0,10,10);
pp=(void *)malloc(size);
setcolor(YELLOW);
setfillstyle(1,4);
fillellipse(8,380,2.5,2.5);
getimage(4,376,12,384,pp);
do
{
gotoxy (1, 1);
setfillstyle (1, 0);
bar (0, 0, 560, 70);
do
{
printf ( "Input speed of bomb(0-84m/s):" );
scanf ( "%f", &v );
if((v>=84)||(v<=0))
{
gotoxy (1, 1);
setfillstyle (1, 0);
bar (0, 0, 500, 70);
printf("Too big! Again!");
}
}
while((v>=90)||(v<=0));
do
{
printf ( "Input angle(0-90):" );
scanf ( "%f", &an );
if((v>=90)||(v<=0))
{
gotoxy (1, 1);
setfillstyle (1, 0);
bar (0, 0, 500, 70);
printf("Too big! Again!");
}
}
while((an>=90)||(an<=0));
for ( i=0; i < (2*v*sin(an*PI/180)/(g*t)); i+=0.5 )
{
x = ( v*i*t*cos(an*PI/180) ) ;
y = ( v*sin(an*PI/180)-(i*t*g)/2 )*t*i;
gotoxy(1,3);
printf ("Ideal range=%-.2fkm\r",x/10);
putimage ( 5+x, 377-y, pp,COPY_PUT );
delay ( 10 );
}
for ( i=0; i < (2*v*sin(an*PI/180)/(g*t)); i+=0.5 )
{
x = ( v*i*t*cos(an*PI/180) ) ;
y = ( v*sin(an*PI/180)-(i*t*g)/2 )*t*i;
putpixel ( 5+x, 373-y, 10);
delay ( 10 );
}
setcolor(15);
a=tan(an*PI/180)+(m*g)/(k*v*cos(an*PI/180));
b=(m*m*g)/(k*k);
c=k/(m*v*cos(an*PI/180));
x1 = ((2*v*v*sin(an*PI/180)*cos(an*PI/180))/(g));
do
{
x0=x1;
x1=x0-( ((exp(a/b*x0))*(1-c*x0)-1 ) / ( (a/b)*(exp(a/b*x0))*(1-c*x0)-c*exp(a/b*x0)) );
++k1;
}
while(fabs(x1-x0)>PR&&k1<MAX);
l = x1;
for ( j=0; j < (-m/k)*log(1-(l*k)/(m*v*cos(an*PI/180)))/t; j+=0.5 )
{
x = (m/k)*(v*cos(an*PI/180))*(1-exp(-(k*j*t)/m));
y = (m/k)*(v*sin(an*PI/180)+m*g/k)*(1-exp(-k*j*t/m))-(m*g/k)*j*t;
gotoxy(1,4);
printf ("True range=%-.2fkm\r",x/10);
putimage ( 5+x, 377-y, pp,COPY_PUT );
delay( 10 );
}
for ( j=0; j < (-m/k)*log(1-(l*k)/(m*v*cos(an*PI/180)))/t; j+=0.5 )
{
x = (m/k)*(v*cos(an*PI/180))*(1-exp(-(k*j*t)/m));
y = (m/k)*(v*sin(an*PI/180)+m*g/k)*(1-exp(-k*j*t/m))-(m*g/k)*j*t;
putpixel ( 5+x, 377-y, 14);
delay( 10 );
}
}
while ( getch( )!=27 );
closegraph ( );
}