Question

HW 5-16-submission format protected View) Microsoft Word (Product age Layout References Mailings Review View Add-Ins nated from an Internet location and might be unsafe. Click for more details. Enable E CSCI 1205-001, Spring 2016 HW #7 Functions and Arrays Name: Dr. Gray Due date: 4-10-16 Output: Required-Output Screen C: n1.exe Time: 19.954s X-Pos: 998.613m Y-Pos: 0.815m Height: 0.881 Time 19.955s X-Pos 998.663m Y-Pos: -0.812m Height: 0.783 Time: 19.956s X-Pos 998.713m Y-Pos: -0.810m Height: e.685 Time 19.957s X-Pos 998.763a V-Pos: -0.807m Height: 0.587 Time 19.958s X-Pos. 998.813m Y-Pos: 0.805m Height: 0.489 Time 19.959s X-Pos: 998.863 Y-pos 0.803m Height: 0.391 Time 19.960s X-Pos: 998. 914m Y-Pos: 0.800m Height: 0.293 Time 19.961 s X-Pos: 998.964m Y-Pos 0.798 m Height: 0.196 Time 19.962s X-Pos: 999.014m Y-Pos: 0.795m Height: 0.098 Time 19.963s X-Pos. 999 .064n Y-Pos: 0.793m Height: 0.000 missed by 1.227 Author: Dr. Gray Azimuth -2.900 Elevation angle 62.900 Program Listing: Your code goes here Pseudocode listing:

HW#5 Functions and Arrays

For HW#5 we will return to the state method of solving the ballistic projectile problem with added twists. The goal will be to hit a target 1000 meters east of your cannon but the wind is blowing from the south. Your initial muzzle velocity is fixed at 110 meters per second, but you can control the elevation and azimuth angles of your aim. Elevation angle is measured up or down. Azimuth angle is measured right or left. Use positive x for east, positive y for north, and positive z for up.

For HW#5 you must use an iterative solution with a time increment of .001 seconds. Even if you could derive an exact solution for the position of the projectile at any instant in time, you may not use it.

You must use arrays to store the x, y, and z components of position, velocity, and acceleration. You must use functions to update the position and velocity arrays and output the current x, y, z position of the projectile after each time increment. You will terminate the iteration when the projectile hits the ground and calculate the horizontal distance from the impact point to the actual target. The closest shot wins bonus points.

Your working variables will be limited to a constant time-increment, aiming inputs and three arrays; position, velocity, and acceleration. Each array will contain 3 elements representing x, y, and z components.

Function prototypes

Void UpdatePosistion(double pos[], double vel[], const double timeInc);

Void UpdateVelocity(double vel[], const double acc[], const double timeInc);

Void OutputPosition(double pos[]);

Variables

const double timeInc = .001 // unit s

const double initialVelocity = 110; // units m/s

const double target[3] = { 1000, 0, 0}; // units m ( x, y, z coordinates) East is positive x

const double acc[3] = { 0, .25, -9.81}; // units m/s2 wind and gravity, North is positive y

double azimuth, elevation, time;

double pos[3], vel[3];

As always you must match the column and precision formatting.

Don’t for get to sign your screens.

HW#5 Ballistics

State Machine Calculation of Trajectories

The objective of homework 5 is to calculate and display the ballistic flight trajectory of a projectile. The problem is simple, an artillery shell is fired from a cannon with an initial velocity, azimuth, and an elevation angle. This produces an initial velocity vector with 3-dimensional components. Over time the force of gravity causes the initial upward velocity to decrease and eventually become downward. From that point on the projectile accelerates downward until it strikes the ground. The time it takes to hit the ground is called the flight time. During the flight time the projectile also has a horizontal component of velocity which cause it to travel downrange. In homework 5 there is also a variable headwind in the horizontal direction which slows the horizontal velocity over time.

In a simple problem there are no horizontal forces acting on the projectile and the entire problem could easily be solved by a simple kinematic equation which could yield exact height and range positions at any instant of time. The addition of a variable headwind significantly complicates the problem and makes ballistic equations difficult to use and certainly beyond the scope of a freshmen class. Fortunately there is another option called a “state machine”.

At any instant of time the projectile has a range and height position, vertical and horizontal components of velocity and vertical and horizontal components of acceleration. Its’ state is completely described by 6 variables. In any small interval of time the change from one state to the next state can be calculated by simple equations. If the time interval between states is small enough the accuracy of this approximate method is quite high.

Equations

newXpos = oldXpos + timeInterval * oldXVel

newYpos = oldYpos + timeInterval * oldYVel

newXvel = oldXvel + timeInterval * Xacceleration

newYvel = oldYvel + timeInterval * Yacceleration

Yacceleration = -9.81 + time

X acceleration = -time // it changes with time

muzzleVelocity = 50;

InitialXVel = muzzleVelocity * cos(elevationAngle)

InitialYvel = muzzleVelocity * sin(elevationAngle)

timeInterval = .001 seconds

Units

Seconds

Meters

Course objectives

You must use functions to update position, velocity, and acceleration.

You must use arrays for the position, velocity, and acceleration vectors.

Bonus points for students who can hit the target.

You must prompt the user for initial input of azimuth and elevation angle.

You must output the time, the height, and the downrange distance at each increment of time. (instantaneous states)

You program must terminate when the projectile strikes the ground.

You must use the “+=” operator.

All data must be output with three decimal places. (use setprecision)

All columns must be aligned. (use setw)

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Executable code :

#include <iostream>
#include <cmath>
#include <iomanip>
using namespace std;


void UpdatePosition(double pos[], double vel[], const double timeInc);
void UpdateVelocity(double vel[], const double acc[], const double timeInc);
void OutputPosition(double pos[]);

int main()
{
const double PI=3.142;
const double timeInc = .001;
const double initialVelocity = 110;
const double target[3] = { 1000, 0, 0};
const double acc[3] = { 0, .25, -9.81};
double azimuth, elevation, time;
double pos[3], vel[3];

for(int i=0;i<3;i++)
{
pos[i]=0;
}

cin>>elevation;
cout<<"enter the azimuth angle"<<endl;
cin>>azimuth;

  
vel[0]=initialVelocity*cos(elevation*PI/180)*cos(azimuth*PI/180);
vel[1]=initialVelocity*cos(elevation*PI/180)*sin(azimuth*PI/180);
vel[2]=initialVelocity*sin(elevation*PI/180);

double flightTime=0.0;
while(pos[2]>0 || flightTime==0)
{
flightTime+=timeInc;
UpdatePosition(pos,vel,timeInc);
UpdateVelocity(vel,acc,timeInc);
cout<<"Time "<<setw(10)<<setprecision(6)<<flightTime<<"s ";
OutputPosition(pos);
}

cout<<"missed by "<<setprecision(4)<<abs(1000-pos[0])<<endl;
cout<<"Azimuth = "<<setprecision(4)<<azimuth<<" Elevation = "<<setprecision(4)<<elevation<<endl;

}

void UpdatePosition(double pos[], double vel[], const double timeInc)
{
pos[0]+=+timeInc*vel[0];
pos[1]+=+timeInc*vel[1];
pos[2]+=timeInc*vel[2];
}
void UpdateVelocity(double vel[], const double acc[], const double timeInc)
{

vel[1]+=timeInc*acc[1];
vel[2]+=timeInc*acc[2];
}
void OutputPosition(double pos[])
{
cout<<"X-POS "<<setw(10)<<setprecision(6)<<pos[0]<<"m ";
cout<<"Y_POS"<<setw(10)<<setprecision(3)<<pos[1]<<"m ";
cout<<"Height"<<setw(10)<<setprecision(3)<<pos[2]<<"m"<<endl;
}

#include #include #include iostream» <cmath> doman!p> 4 using namespace std; 7 void UpdatePosition(double pos[l, double vel[l

Add a comment
Know the answer?
Add Answer to:
HW#5 Functions and Arrays For HW#5 we will return to the state method of solving the...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • LEARN MORE REMARKS This example emphasizes the independence of the x- and y components in projectile...

    LEARN MORE REMARKS This example emphasizes the independence of the x- and y components in projectile motion problems. QUESTION How does the magnitude of the velocity vector at impact compare with the magnitude of the initial velocity vector? O It is greater at impact. They are the same since the magnitude of the vertical component of velocity is the same at each height on the way up and on the way down. O It is greater initially O They are...

  • Create a program that plots the trajectory, from the initial height to the ground, of a...

    Create a program that plots the trajectory, from the initial height to the ground, of a projectile accelerating both in the horizontal and vertical directions. -Matlab Code PROBLEM 4: In your physics class, projectile motion has two components: constant-velocity motion in the horizontal direction and free-fall motion in the vertical direction. However, in reality, the horizontal motion has acceleration due to air resistance, wind, and other factors. The goal of this problem is to visualize the trajectory of a projectile...

  • 5. General Motion with Unit Vectors and Components An object undergoes the following consecutive displacements: s...

    5. General Motion with Unit Vectors and Components An object undergoes the following consecutive displacements: s (2i +3j +5k)m,s2 (6i- 9j + 2k)m, and s3 (10i 8j -k)m. a) Find the resultant displacement in terms of unit vectors and components. b) State the magnitude of the resultant displacement. 2. Suppose a hiker travels 5 km southwest from their camp. Then, the hiker travels 2 km 75° north of east. a) Find the displacement of the hiker form their camp. b)...

  • C++ Please     Contact list - functions & parallel arrays/CStrings No Vectors can be used since we...

    C++ Please     Contact list - functions & parallel arrays/CStrings No Vectors can be used since we haven't learned them yet !! A contact list is a place where you can store a specific information with other associated information such as a phone number, email address, birthday, etc. Write a program that will read 5 data pairs into two parallel arrays. Data pairs consist of a name (as a CString) and a GPA (double). That list is followed by a name,...

  • Using Python a) Add a function to the Projectle class below so it can print out...

    Using Python a) Add a function to the Projectle class below so it can print out the current status seconds, position, and total velocity (not the x,y components) It should work as ilustrated bekow, so you can directly print the instance of the Projectie object b) If the projectile reaches ts maximum height automatically print a message with the current time and height. Make sure this only prints once if time is updated continucusty You do not need to calculate...

  • EXPLORE A projectile is launched with a launch angle of 30° with respect to the horizontal...

    EXPLORE A projectile is launched with a launch angle of 30° with respect to the horizontal direction and with an initial speed of 10 m/s. s0 (A) How do the vertical and horizontal components of the projectile's velocity vary with time? 40 35 (B) How long does it remain in flight? 25 (C) For a given launch speed, what launch angle produces the longest time of flight? 15 10 toy CONCEPTUALIZE Consider the projectile to be a point mass that...

  • EXPLORE A projectile is launched with a launch angle of 30° with respect to the horizontal...

    EXPLORE A projectile is launched with a launch angle of 30° with respect to the horizontal direction and with an initial speed of 40 m/s. (A) How do the vertical and horizontal components of the projectile's velocity vary with time? (B) How long does it remain in flight? (C) For a given launch speed, what launch angle produces the longest time of flight? CONCEPTUALIZE Consider the projectile to be a point mass that starts with an initial velocity, upward and...

  • CODE GIVEN % Create a program to plot the motion of the ping pong ball with...

    CODE GIVEN % Create a program to plot the motion of the ping pong ball with drag. % The program will take inputs for velocity in m/s and angle of launch. % note that with a high speed camera I estmated a launch speed for a ping % pong ball could be 30 m/s. vel=30; %m/s angle=60; % convert the degrees into radians so MATLAB likes it angle=angle*pi/180; % set initial values (time, distance, mass, gravity, drag) x(1)=0; % meters...

  • 7. Do the projectile motion General Motion with Unit Vectors and Components An object undergoes the...

    7. Do the projectile motion General Motion with Unit Vectors and Components An object undergoes the following consecutive displacements: s (2i +3j +5k)m,s2 (6i- 9j + 2k)m, and s3 (10i 8j -k)m. a) Find the resultant displacement in terms of unit vectors and components. b) State the magnitude of the resultant displacement. 2. Suppose a hiker travels 5 km southwest from their camp. Then, the hiker travels 2 km 75° north of east. a) Find the displacement of the hiker...

  • 7. General Motion with Unit Vectors and Components An object undergoes the following consecutive displacements: s...

    7. General Motion with Unit Vectors and Components An object undergoes the following consecutive displacements: s (2i +3j +5k)m,s2 (6i- 9j + 2k)m, and s3 (10i 8j -k)m. a) Find the resultant displacement in terms of unit vectors and components. b) State the magnitude of the resultant displacement. 2. Suppose a hiker travels 5 km southwest from their camp. Then, the hiker travels 2 km 75° north of east. a) Find the displacement of the hiker form their camp. b)...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT