-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtrajecto1.cpp
More file actions
executable file
·89 lines (79 loc) · 2.09 KB
/
Copy pathtrajecto1.cpp
File metadata and controls
executable file
·89 lines (79 loc) · 2.09 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
#include <ccbp.h>
#include <math.h>
#include <stdio.h>
#include <conio.h>
#define PR 0.001
#define MAX 1000
#define PI 3.14
float f(float u)
{
float a,b,c,g=9.88,k=2.2,an=60,m=12,v=80;
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));
return ((exp(a/b*u))*(1-c*u)-1);
}
float df(float u)
{
float a,b,c,g=9.88,an=60,m=12,v=80,k=2.2;
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));
return ((a/b)*(exp(a/b*u))*(1-c*u)-c*exp(a/b*u));
}
float distance(float x)
{
int k1=1;
float x0;
do
{
x0=x;
x=x0-(f(x0)/df(x0));
++k1;
}
while(fabs(x-x0)>PR&&k1<MAX);
return (x);
}
void main ( )
{
float j, i, l, d, x, y, t = 0.05, g=9.88, k=2.2;
int m=12, v=80, an=60, gd = DETECT, gm;
d = ((2*v*v*sin(an*PI/180)*cos(an*PI/180))/(g));
l = distance (d);
initgraph ( &gd, &gm, "c:\\tc" );
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, 90, 640, 365 );
coordc ( 50, 365, 550, 0, 550, 15 );
coordc ( 50, 365, 270, 90, 200, 15 );
outhzxy3 (600, 365, " x ", 3, 0, 15 );
outhzxy3 (50, 95, " y ", 3, 0, 15 );
outhzxy3 (40, 365, " o ", 3, 0, 15 );
outhzxy3 ( 50, 380, "x=v*cos(angle*t), y=v*sin(angle*t)-(1/2)*g*t*t", 2, 0, 2 );
outhzxy3 ( 50, 390, "x=(m/k)*(v*cos(angle))*(1-exp(-(k*t)/m))", 2, 0, 2 );
outhzxy3 ( 50, 400, "y=(m/k)*(v*sin(angle)+m*g/k)*(1-exp(-k*t/m))-(m*g/k)*t", 2, 0, 2 );
do
{ setcolor (12);
for ( i=0; i < (2*v*sin(an*PI/180)/(g*t)); i+=0.035 )
{
x = ( v*i*t*cos(an*PI/180) ) ;
y = ( v*sin(an*PI/180)-(i*t*g)/2 )*t*i;
gotoxy(1,1);
printf ("Ideal range=%f\r",x);
putpixel ( 50+x, 365-y, 12 );
delay ( 0 );
}
setcolor(15);
for ( j=0; j < (-m/k)*log(1-(l*k)/(m*v*cos(an*PI/180)))/t; j+=0.035 )
{
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,2);
printf ("True range=%f\r",x);
putpixel ( 50+x, 365-y, 15 );
delay( 0 );
}
}while ( getch( )!=27 );
closegraph ( );
}