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
|
#include <iostream>
#include <cmath>
using std::cin;
using std::endl;
using std::cout;
float New_Position(float[],float[],float);
int main()
{
float time, frame, t = 1.5, i[] = {0,0}, a[] = {0,0},new_Position[] = {0,0};
//user input
cout << "Enter initial Pixel Point for the X coordinate: "; // intial Pixel Point for X coordinate
cin >> i[0];
cout << "Enter initial Pixel Point for the Y coordinate: "; // intial Pixel Point for Y coordinate
cin >> i[1];
cout << "Enter Acceleration for the X vector: "; // Acceleration for X Vector (pixels / sec^2)
cin >> a[0];
cout << "Enter Acceleration for Y vector: "; // Acceleration for Y vector (pixels / sec^2)
cin >> a[1];
cout << endl << endl;
cout << "Initial point (x,y): " << "(" << i[0]<< "," << i[1]<< ")" << endl << endl; //dsplays the initial point at frame 0
//for loop to cycle throug 45 frames while showing time in seconds.
for ( frame=1; (time = frame/30) <= t; frame++)
{
new_Position[2] = New_Position(i,a,time); //calls function g, which does the calculation for new point
//output for the program
cout << endl << "Frame: " << frame << " The point is now at: " << "(" << new_Position[0] << "," << new_Position[1] << ")" << endl;
//if we wanted time too:
//cout<<"it took: "<<time<<" secs"<<endl;
}
return 0;
}
//function based on final point being calculated by accumilating
//the initial point and adding acceleration*time.
float New_Position(float i[], float a[], float t)
{
int n = 2; // going back to lab 3, n must = 2 for arrays to work properly
int k = 0;
//float newPosition = 0;
//for (int k=0; k <= n-1; k++)
//{
i[k] = i[k] + a[k]*t;//formula that finds where the new point is from old point given accel and time.
//New_Position = Old_Position + acceleration * time
//}
return i[2];
}
/*static float New_Position (float Old_Position, float v, float t)
{
return Old_Position + v*t ;
}*/
|