Software Requirements Specification for Projectile

Samuel J. Crawford, Brooks MacLachlan, and W. Spencer Smith

Reference Material

This section records information for easy reference.

Table of Units

The unit system used throughout is SI (Système International d'Unités). In addition to the basic units, several derived units are also used. For each unit, Tab: ToU lists the symbol, a description and the SI name.

Symbol
Description SI Name
m length metre
rad angle radian
s time second

Table of Symbols

The symbols used in this document are summarized in Tab: ToS along with their units. Throughout the document, symbols in bold will represent vectors, and scalars otherwise. The symbols are listed in alphabetical order. For vector quantities, the units shown are for each component of the vector.

Symbol
Description Units
$a$ Scalar acceleration $\frac{\text{m}}{\text{s}^{2}}$
ac Constant acceleration m/s2
ax x-component of acceleration m/s2
${a_{x}^{c}}$ $x$-component of acceleration $\frac{\text{m}}{\text{s}^{2}}$
ay y-component of acceleration m/s2
ayc y-component of constant acceleration m/s2
a Acceleration m/s2
ac Constant acceleration vector m/s2
doffset Distance between the target position and the landing position m
g Gravitational acceleration m/s2
p Scalar position m
pi Initial position m
pland Landing position m
ptarget Target position m
px x-component of position m
pxi x-component of initial position m
py y-component of position m
pyi y-component of initial position m
p Position m
s Output message as a string --
t Time s
tflight Flight duration s
v Speed m/s
vi Initial speed m/s
vlaunch Launch speed m/s
vx x-component of velocity m/s
vxi x-component of initial velocity m/s
vy y-component of velocity m/s
vyi y-component of initial velocity m/s
v Velocity m/s
vi Initial velocity m/s
ε Hit tolerance --
θ Launch angle rad
π Ratio of circumference to diameter for any circle --

Abbreviations and Acronyms

Abbreviation
Full Form
1D One-Dimensional
2D Two-Dimensional
A Assumption
DD Data Definition
GD General Definition
GS Goal Statement
IM Instance Model
PS Physical System Description
R Requirement
SRS Software Requirements Specification
TM Theoretical Model
Uncert. Typical Uncertainty

Introduction

Projectile motion is a common problem in physics. Therefore, it is useful to have a program to solve and model these types of problems. The program documented here is called Projectile.

The following section provides an overview of the Software Requirements Specification (SRS) for Projectile. This section explains the purpose of this document, the scope of the system, the characteristics of the intended reader, and the organization of the document.

Scope of Requirements

The scope of the requirements includes the analysis of a two-dimensional (2D) projectile motion problem with constant acceleration. Given the appropriate inputs, Projectile determines if the projectile hits the target.

Specific System Description

This section first presents the problem description, which gives a high-level view of the problem to be solved. This is followed by the solution characteristics specification, which presents the assumptions, theories, and definitions that are used.

Problem Description

A system is needed to efficiently and correctly predict the landing position of a projectile.

Terminology and Definitions

This subsection provides a list of terms that are used in the subsequent sections and their meaning, with the purpose of reducing ambiguity and making it easier to correctly understand the requirements.

  • Launcher: Where the projectile is launched from and the device that does the launching.
  • Projectile: The object to be launched at the target.
  • Target: Where the projectile should be launched to.
  • Gravity: The force that attracts one physical body with mass to another.
  • Cartesian coordinate system: A coordinate system that specifies each point uniquely in a plane by a set of numerical coordinates, which are the signed distances to the point from two fixed perpendicular oriented lines, measured in the same unit of length (from cartesianWiki).
  • Rectilinear: Occuring in one dimension.

Physical System Description

The physical system of Projectile, as shown in Fig:Launch, includes the following elements:

PS1: The launcher.

PS2: The projectile (with initial velocity vi and launch angle θ).

PS3: The target.

The physical system

Goal Statements

Given the initial velocity vector of the projectile, the goal statements are:

targetHit: Determine if the projectile hits the target.

Solution Characteristics Specification

The instance models that govern Projectile are presented in Section: Instance Models. The information to understand the meaning of the instance models and their derivation is also presented, so that the instance models can be verified.

Assumptions

This section simplifies the original problem and helps in developing the theoretical models by filling in the missing information for the physical system. The assumptions refine the scope by providing more detail.

twoDMotion: The projectile motion is two-dimensional (2D). (RefBy: GD: velVec and GD: posVec.)
cartSyst: A Cartesian coordinate system is used (from A: neglectCurv). (RefBy: GD: velVec and GD: posVec.)
yAxisGravity: The direction of the y-axis is directed opposite to gravity. (RefBy: IM: calOfLandingTime, IM: calOfLandingDist, and A: accelYGravity.)
launchOrigin: The launcher is coincident with the origin. (RefBy: IM: calOfLandingTime and IM: calOfLandingDist.)
targetXAxis: The target lies on the x-axis (from A: neglectCurv). (RefBy: IM: calOfLandingTime.)
posXDirection: The positive x-direction is from the launcher to the target. (RefBy: IM: calOfLandingTime, IM: offsetIM, IM: messageIM, and IM: calOfLandingDist.)
constAccel: The acceleration is constant (from A: accelXZero, A: accelYGravity, A: neglectDrag, and A: freeFlight). (RefBy: GD: velVec and GD: posVec.)
accelXZero: The acceleration in the x-direction is zero. (RefBy: IM: calOfLandingDist and A: constAccel.)
accelYGravity: The acceleration in the y-direction is the acceleration due to gravity (from A: yAxisGravity). (RefBy: IM: calOfLandingTime and A: constAccel.)
neglectDrag: Air drag is neglected. (RefBy: A: constAccel.)
pointMass: The size and shape of the projectile are negligible, so that it can be modelled as a point mass. (RefBy: GD: rectVel and GD: rectPos.)
freeFlight: The flight is free; there are no collisions during the trajectory of the projectile. (RefBy: A: constAccel.)
neglectCurv: The distance is small enough that the curvature of the Earth can be neglected. (RefBy: A: targetXAxis and A: cartSyst.)
timeStartZero: Time starts at zero. (RefBy: GD: velVec, IM: calOfLandingTime, GD: rectVel, GD: rectPos, and GD: posVec.)

Theoretical Models

This section focuses on the general equations and laws that Projectile is based on.

Refname
TM:acceleration
Label Acceleration
Equation $$\mathbf{a}=\frac{\,d\mathbf{v}}{\,dt}$$
Description a is the acceleration (m/s2)
t is the time (s)
v is the velocity (m/s)
Source accelerationWiki and hibbeler2004 (pg. 7)
RefBy GD: rectVel
Refname
TM:velocity
Label Velocity
Equation $$\mathbf{v}=\frac{\,d\mathbf{p}}{\,dt}$$
Description v is the velocity (m/s)
t is the time (s)
p is the position (m)
Source velocityWiki and hibbeler2004 (pg. 6)
RefBy GD: rectPos

General Definitions

This section collects the laws and equations that will be used to build the instance models.

Refname
GD:rectVel
Label Rectilinear (1D) velocity as a function of time for constant acceleration
Units m/s
Equation $$v={v^{i}}+{a^{c}} t$$
Description v is the speed (m/s)
vi is the initial speed (m/s)
ac is the constant acceleration (m/s2)
t is the time (s)
Source hibbeler2004 (pg. 8)
RefBy GD: velVec and GD: rectPos

Detailed derivation of rectilinear velocity:

Assume we have rectilinear motion of a particle (of negligible size and shape, from A: pointMass); that is, motion in a straight line. The velocity is v and the acceleration is a. The motion in TM: acceleration is now one-dimensional with a constant acceleration, represented by ac. The initial velocity (at t = 0, from A: timeStartZero) is represented by vi. From TM: acceleration, using the above symbols we have:

$${a^{c}}=\frac{\,dv}{\,dt}$$

Rearranging and integrating, we have:

$$\int_{{v^{i}}}^{v}{1}\,dv=\int_{0}^{t}{{a^{c}}}\,dt$$

Performing the integration, we have the required equation:

$$v={v^{i}}+{a^{c}} t$$
Refname
GD:rectPos
Label Rectilinear (1D) position as a function of time for constant acceleration
Units m
Equation $$p={p^{i}}+{v^{i}} t+\frac{{a^{c}} t^{2}}{2}$$
Description p is the scalar position (m)
pi is the initial position (m)
vi is the initial speed (m/s)
t is the time (s)
ac is the constant acceleration (m/s2)
Source hibbeler2004 (pg. 8)
RefBy GD: posVec

Detailed derivation of rectilinear position:

Assume we have rectilinear motion of a particle (of negligible size and shape, from A: pointMass); that is, motion in a straight line. The position is p and the velocity is v. The motion in TM: velocity is now one-dimensional. The initial position (at t = 0, from A: timeStartZero) is represented by pi. From TM: velocity, using the above symbols we have:

$$v=\frac{\,dp}{\,dt}$$

Rearranging and integrating, we have:

$$\int_{{p^{i}}}^{p}{1}\,dp=\int_{0}^{t}{v}\,dt$$

From GD: rectVel we can replace v:

$$\int_{{p^{i}}}^{p}{1}\,dp=\int_{0}^{t}{{v^{i}}+{a^{c}} t}\,dt$$

Performing the integration, we have the required equation:

$$p={p^{i}}+{v^{i}} t+\frac{{a^{c}} t^{2}}{2}$$
Refname
GD:velVec
Label Velocity vector as a function of time for 2D motion under constant acceleration
Units m/s
Equation $$

\mathbf{v}=\begin{bmatrix} {{v_{x}}^{i}}+{{a_{x}}^{c}} t\\ {{v_{y}}^{i}}+{{a_{y}}^{c}} t \end{bmatrix} $$| |Description|v is the velocity (m/s)
vxi is the x-component of initial velocity (m/s)
axc is the x-component of constant acceleration (m/s2)
t is the time (s)
vyi is the y-component of initial velocity (m/s)
ayc is the y-component of constant acceleration (m/s2)| |Source|--| |RefBy||

Detailed derivation of velocity vector:

For a two-dimensional Cartesian coordinate system (A: twoDMotion and A: cartSyst), we can represent the velocity vector as $\mathbf{v}=\begin{bmatrix} {v_{x}}\\ {v_{y}} \end{bmatrix}$ and the acceleration vector as $\mathbf{a}=\begin{bmatrix} {a_{x}}\\ {a_{y}} \end{bmatrix}$ . The acceleration is assumed to be constant (A: constAccel) and the constant acceleration vector is represented as ${\mathbf{a}^{c}}=\begin{bmatrix} {{a_{x}}^{c}}\\ {{a_{y}}^{c}} \end{bmatrix}$ . The initial velocity (at t = 0, from A: timeStartZero) is represented by ${\mathbf{v}^{i}}=\begin{bmatrix} {{v_{x}}^{i}}\\ {{v_{y}}^{i}} \end{bmatrix}$ . Since we have a Cartesian coordinate system, GD: rectVel can be applied to each coordinate of the velocity vector to yield the required equation:

$$ \mathbf{v}=\begin{bmatrix} {{v_{x}}^{i}}+{{a_{x}}^{c}} t\\ {{v_{y}}^{i}}+{{a_{y}}^{c}} t \end{bmatrix} $$
Refname
GD:posVec
Label Position vector as a function of time for 2D motion under constant acceleration
Units m/s
Equation $$

\mathbf{p}=\begin{bmatrix} {{p_{x}}^{i}}+{{v_{x}}^{i}} t+\frac{{{a_{x}}^{c}} t^{2}}{2}\\ {{p_{y}}^{i}}+{{v_{y}}^{i}} t+\frac{{{a_{y}}^{c}} t^{2}}{2} \end{bmatrix} $$| |Description|p is the position (m)
pxi is the x-component of initial position (m)
vxi is the x-component of initial velocity (m/s)
t is the time (s)
axc is the x-component of constant acceleration (m/s2)
pyi is the y-component of initial position (m)
vyi is the y-component of initial velocity (m/s)
ayc is the y-component of constant acceleration (m/s2)| |Source|--| |RefBy|IM: calOfLandingTime and IM: calOfLandingDist|

Detailed derivation of position vector:

For a two-dimensional Cartesian coordinate system (A: twoDMotion and A: cartSyst), we can represent the position vector as $\mathbf{p}=\begin{bmatrix} {p_{x}}\\ {p_{y}} \end{bmatrix}$ , the velocity vector as $\mathbf{v}=\begin{bmatrix} {v_{x}}\\ {v_{y}} \end{bmatrix}$ , and the acceleration vector as $\mathbf{a}=\begin{bmatrix} {a_{x}}\\ {a_{y}} \end{bmatrix}$ . The acceleration is assumed to be constant (A: constAccel) and the constant acceleration vector is represented as ${\mathbf{a}^{c}}=\begin{bmatrix} {{a_{x}}^{c}}\\ {{a_{y}}^{c}} \end{bmatrix}$ . The initial velocity (at t = 0, from A: timeStartZero) is represented by ${\mathbf{v}^{i}}=\begin{bmatrix} {{v_{x}}^{i}}\\ {{v_{y}}^{i}} \end{bmatrix}$ . Since we have a Cartesian coordinate system, GD: rectPos can be applied to each coordinate of the position vector to yield the required equation:

$$\mathbf{p}=\begin{bmatrix} {{p_{x}}^{i}}+{{v_{x}}^{i}} t+\frac{{{a_{x}}^{c}} t^{2}}{2}\\ {{p_{y}}^{i}}+{{v_{y}}^{i}} t+\frac{{{a_{y}}^{c}} t^{2}}{2} \end{bmatrix}$$

Data Definitions

This section collects and defines all the data needed to build the instance models.

Refname
DD:vecMag
Label Speed
Symbol v
Units m/s
Equation $$

v=|\mathbf{v}| $$| |<b>Description</b>|<em>v</em> is the speed (m/s) <br> <em><b>v</b></em> is the velocity (m/s)| |<b>Notes</b>|For a given velocity vector $\mathbf{v}$, the magnitude of the vector ($|\mathbf{v}|$) is the scalar called speed.| |Source|--| |RefBy|DD: speedIY and DD: speedIX|

Refname
DD:speedIX
Label x-component of initial velocity
Symbol vxi
Units m/s
Equation $$

{{v_{x}}^{i}}={v^{i}} \cos\left(θ\right) $$| |Description|vxi is the x-component of initial velocity (m/s)
vi is the initial speed (m/s)
θ is the launch angle (rad)</li>| |Notes|vi is from DD: vecMag.
θ is shown in Fig:Launch.| |Source|--| |RefBy|IM: calOfLandingDist|

Refname
DD:speedIY
Label y-component of initial velocity
Symbol vyi
Units m/s
Equation $$

{{v_{y}}^{i}}={v^{i}} \sin\left(θ\right) $$| |Description|vyi is the y-component of initial velocity (m/s)
vi is the initial speed (m/s)
θ is the launch angle (rad)| |Notes|vi is from DD: vecMag.
θ is shown in Fig:Launch.| |Source|--| |RefBy|IM: calOfLandingTime|

Instance Models

This section transforms the problem defined in Section: Problem Description into one which is expressed in mathematical terms. It uses concrete symbols defined in Section: Data Definitions to replace the abstract symbols in the models identified in Section: Theoretical Models and Section: General Definitions.

Refname
IM:calOfLandingTime
Label Calculation of landing time
Input vlaunch, θ
Output tflight
Input Constraints $${v_{launch}}>0$$ $$0<θ<\frac{π}{2}$$
Output Constraints $${t_{flight}}>0$$
Equation $$

{t{flight}}=\frac{2 {v{launch}} \sin\left(θ\right)}{g} $$| |<b>Description</b>|<em>t<sub>flight</sub></em> is the flight duration (s) <br> <em>v<sub>launch</sub></em> is the launch speed (m/s) <br> <em>θ</em> is the launch angle (rad) <br> <em>g</em> is the gravitational acceleration (m/s<sup>2</sup>)| |<b>Notes</b>|The constraint $0<θ<\frac{π}{2}$ is from <a href=#posXDirection>A: posXDirection</a> and <a href=#yAxisGravity>A: yAxisGravity</a>, and is shown in <a href=#Figure:Launch>Fig:Launch</a>. <br> <em>g</em> is defined in <a href=#Sec:AuxConstants>Section: Values of Auxiliary Constants</a>. <br> The constraint ${t_{flight}}>0$ is from A: timeStartZero.| |Source|--| |RefBy|IM: calOfLandingDist and FR: Calculate-Values|

Detailed derivation of flight duration:

We know that pyi = 0 (A: launchOrigin) and ayc = −g (A: accelYGravity). Substituting these values into the y-direction of GD: posVec gives us:

$${p_{y}}={{v_{y}}^{i}} t-\frac{g t^{2}}{2}$$

To find the time that the projectile lands, we want to find the t value (tflight) where py = 0 (since the target is on the x-axis from A: targetXAxis). From the equation above we get:

$${{v_{y}}^{i}} {t_{flight}}-\frac{g {t_{flight}}^{2}}{2}=0$$

Dividing by tflight (with the constraint tflight > 0) gives us:

$${{v_{y}}^{i}}-\frac{g {t_{flight}}}{2}=0$$

Solving for tflight gives us:

$${t_{flight}}=\frac{2 {{v_{y}}^{i}}}{g}$$

From DD: speedIY (with vi = vlaunch) we can replace vyi:

$${t_{flight}}=\frac{2 {v_{launch}} \sin\left(θ\right)}{g}$$
Refname
IM:calOfLandingDist
Label Calculation of landing position
Input ${v_{launch}}$, $θ$
Output ${p_{land}}$
Input Constraints $${v_{launch}}>0$$ $$0<θ<\frac{π}{2}$$
Output Constraints $${p_{land}}>0$$
Equation $$

{p{land}}=\frac{2 {v{launch}}^{2} \sin\left(θ\right) \cos\left(θ\right)}{g} $$| |<b>Description</b>|<em>p<sub>land</sub></em> is the landing position (m) </br> <em>v<sub>launch</sub></em> is the launch speed (m/s) <br> <em>θ</em> is the launch angle (rad) <br> <em>g</em> is the gravitational acceleration (m/s<sup>2</sup>)| |<b>Notes</b>|The constraint $0<θ<\frac{π}{2}$ is from <a href=#posXDirection>A: posXDirection</a> and <a href=#yAxisGravity>A: yAxisGravity</a>, and is shown in <a href=#Figure:Launch>Fig:Launch</a>. <br> <em>g</em> is defined in <a href=#Sec:AuxConstants>Section: Values of Auxiliary Constants</a>. <br> The constraint ${p_{land}}>0$ is from A: posXDirection.| |Source|--| |RefBy|IM: offsetIM and FR: Calculate-Values|

Detailed derivation of landing position:

We know that pxi = 0 (A: launchOrigin) and axc = 0 (A: accelXZero). Substituting these values into the x-direction of GD: posVec gives us:

$${p_{x}}={{v_{x}}^{i}} t$$

To find the landing position, we want to find the px value (pland) at flight duration (from IM: calOfLandingTime):

$${p_{land}}=\frac{{{v_{x}}^{i}}\cdot{}2 {v_{launch}} \sin\left(θ\right)}{g}$$

From DD: speedIX (with vi = vlaunch) we can replace vxi:

$${p_{land}}=\frac{{v_{launch}} \cos\left(θ\right)\cdot{}2 {v_{launch}} \sin\left(θ\right)}{g}$$

Rearranging this gives us the required equation:

$${p_{land}}=\frac{2 {v_{launch}}^{2} \sin\left(θ\right) \cos\left(θ\right)}{g}$$
Refname
IM:offsetIM
Label Offset
Input ${p_{land}}$, ${p_{target}}$
Output ${d_{offset}}$
Input Constraints $${p_{land}}>0$$ $${p_{target}}>0$$
Output Constraints
Equation $$

{d{offset}}={p{land}}-{p_{target}} $$| |Description|doffset is the distance between the target position and the landing position (m)
pland is the landing position (m)
ptarget is the target position (m)| |Notes|pland is from IM: calOfLandingDist.
The constraints pland > 0 and ptarget > 0 are from A: posXDirection.| |Source|--| |RefBy|FR: Output-Values, IM: messageIM, and FR: Calculate-Values|

Refname
IM:messageIM
Label Output message
Input ${d_{offset}}$, ${p_{target}}$
Output $s$
Input Constraints $${p_{target}}>0$$ $${d_{offset}}>-{p_{land}}$$
Output Constraints
Equation $$

s=\begin{cases} \text{"The target was hit."}, & |\frac{{d_{offset}}}{{p_{target}}}|<ε\\ \text{"The projectile fell short."}, & {d_{offset}}<0\\ \text{"The projectile went long."}, & {d_{offset}}>0 \end{cases} $$| |Description|s is the output message as a string (Unitless)
doffset is the distance between the target position and the landing position (m)
ptarget is the target position (m)
ε is the hit tolerance (Unitless)| |Notes|doffset is from IM: offsetIM.
The constraint ptarget > 0 is from A: posXDirection.
The constraint doffset > −pland is from the fact that pland > 0, from A: posXDirection.
ε is defined in Section: Values of Auxiliary Constants.| |Source|--| |RefBy|FR: Output-Values and FR: Calculate-Values|

Data Constraints

Table:InDataConstraints shows the data constraints on the input variables. The column for physical constraints gives the physical limitations on the range of values that can be taken by the variable. The uncertainty column provides an estimate of the confidence with which the physical quantities can be measured. This information would be part of the input if one were performing an uncertainty quantification exercise. The constraints are conservative, to give the user of the model the flexibility to experiment with unusual situations. The column of typical values is intended to provide a feel for a common scenario.

Var
Physical Constraints Typical Value Uncert.
${p_{target}}$ ${p_{target}}>0$ $1000$ m 10$\%$
${v_{launch}}$ ${v_{launch}}>0$ $100$ $\frac{\text{m}}{\text{s}}$ 10$\%$
$θ$ $0<θ<\frac{π}{2}$ $\frac{π}{4}$ rad 10$\%$
Input Data Constraints

Properties of a Correct Solution

Table:OutDataConstraints shows the data constraints on the output variables. The column for physical constraints gives the physical limitations on the range of values that can be taken by the variable.

Var
Physical Constraints
${p_{land}}$ ${p_{land}}>0$
${d_{offset}}$ ${d_{offset}}>-{p_{land}}$
Output Data Constraints

Requirements

This section provides the functional requirements, the tasks and behaviours that the software is expected to complete, and the non-functional requirements, the qualities that the software is expected to exhibit.

Functional Requirements

This section provides the functional requirements, the tasks and behaviours that the software is expected to complete.

Input-Parameters: Input the quantities from Table:ReqInputs, which define the launch angle, launch speed, and target position.
Verify-Parameters: Check the entered input parameters to ensure that they do not exceed the data constraints mentioned in Section: Data Constraints. If any of the input parameters are out of bounds, an error message is displayed and the calculations stop.
Calculate-Values: Calculate the following quantities: tflight (from IM: calOfLandingTime), pland (from IM: calOfLandingDist), doffset (from IM: offsetIM), and s (from IM: messageIM).
Output-Values: Output s (from IM: messageIM) and doffset (from IM: offsetIM).
Symbol
Description Units
ptarget Target position m
vlaunch Launch speed m/s
θ Launch angle rad
Required Inputs following FR: Input-Parameters

Non-Functional Requirements

This section provides the non-functional requirements, the qualities that the software is expected to exhibit.

Correct: The outputs of the code have the properties described in Section: Properties of a Correct Solution.
Verifiable: The code is tested with complete verification and validation plan.
Understandable: The code is modularized with complete module guide and module interface specification.
Reusable: The code is modularized.
Maintainable: The traceability between requirements, assumptions, theoretical models, general definitions, data definitions, instance models, likely changes, unlikely changes, and modules is completely recorded in traceability matrices in the SRS and module guide.
Portable: The code is able to be run in different environments.

Traceability Matrices and Graphs

The purpose of the traceability matrices is to provide easy references on what has to be additionally modified if a certain component is changed. Every time a component is changed, the items in the column of that component that are marked with an "X" should be modified as well. Table:TraceMatAvsAll shows the dependencies of data definitions, theoretical models, general definitions, instance models, requirements, likely changes, and unlikely changes on the assumptions. Table:TraceMatRefvsRef shows the dependencies of data definitions, theoretical models, general definitions, and instance models with each other. Table:TraceMatAllvsR shows the dependencies of requirements, goal statements on the data definitions, theoretical models, general definitions, and instance models.

Traceability Matrix Showing the Connections Between Assumptions and Other Items
Traceability Matrix Showing the Connections Between Items and Other Sections
Traceability Matrix Showing the Connections Between Requirements, Goal Statements and Other Items

Values of Auxiliary Constants

This section contains the standard values that are used for calculations in Projectile.

Symbol
Description Value Unit
g gravitational acceleration 9.8 m/s2
ε hit tolerance 2.0% --
π ratio of circumference to diameter for any circle 3.14159265 --
Auxiliary Constants

References

[1]: Hibbeler, R. C. Engineering Mechanics: Dynamics. Pearson Prentice Hall, 2004. Print.
[2]: Wikipedia Contributors. Acceleration. June, 2019. https://en.wikipedia.org/wiki/Acceleration.
[3]: Wikipedia Contributors. Cartesian coordinate system. June, 2019. https://en.wikipedia.org/wiki/Cartesian_coordinate_system.
[4]: Wikipedia Contributors. Velocity. June, 2019. https://en.wikipedia.org/wiki/Velocity.

In [59]:
from __future__ import print_function
import sys
import math

In [60]:
class InputParameters:
    None

In [61]:
## \brief Reads input from a file with the given file name
# \param filename No description given
# \param inParams No description given
def get_input(filename, inParams):
    infile = open(filename, "r")
    infile.readline()
    inParams.v_launch = float(infile.readline())
    infile.readline()
    inParams.angle = float(infile.readline())
    infile.readline()
    inParams.p_target = float(infile.readline())
    infile.close()

In [62]:
## \brief Writes the output values to output.txt
# \param s output message as a string
# \param d_offset distance between the target position and the landing position
def write_output(s, d_offset):
    outputfile = open("output.txt", "w")
    print("s = ", end='', file=outputfile)
    print(s, file=outputfile)
    print("d_offset = ", end='', file=outputfile)
    print(d_offset, file=outputfile)
    outputfile.close()

In [63]:
## \brief Calculates flight duration
# \param inParams No description given
def func_t_flight(inParams):
    return ((2 * (inParams.v_launch * math.sin(inParams.angle))) / 9.8)

## \brief Calculates landing position
# \param inParams No description given
def func_p_land(inParams):
    return ((2 * ((inParams.v_launch ** 2) * (math.sin(inParams.angle) * math.cos(inParams.angle)))) / 9.8)

## \brief Calculates distance between the target position and the landing position
# \param inParams No description given
# \param p_land landing position
def func_d_offset(inParams, p_land):
    return (p_land - inParams.p_target)

## \brief Calculates output message as a string
# \param inParams No description given
# \param d_offset distance between the target position and the landing position
def func_s(inParams, d_offset):
    if ((math.fabs((d_offset / inParams.p_target)) < 2.0e-2)) :
        return "The target was hit."
    elif ((d_offset < 0)) :
        return "The projectile fell short."
    elif ((d_offset > 0)) :
        return "The projectile went long."
    else :
        raise Exception("Undefined case encountered in function func_s")

In [64]:
## \brief Verifies that input values satisfy the physical constraints and software constraints
# \param inParams No description given
def input_constraints(inParams):
    if (not((inParams.v_launch > 0))) :
        print("Warning: constraint violated")
    if (not(((0 < inParams.angle) and (inParams.angle < (3.14159265 / 2))))) :
        print("Warning: constraint violated")
    if (not((inParams.p_target > 0))) :
        print("Warning: constraint violated")

In [65]:
#main
def main():
    filename = "input.txt"
    inParams = InputParameters()
    get_input(filename, inParams)
    input_constraints(inParams)
    t_flight = func_t_flight(inParams)
    p_land = func_p_land(inParams)
    d_offset = func_d_offset(inParams, p_land)
    s = func_s(inParams, d_offset)
    write_output(s, d_offset)
    print("s = ", s)
    print("d_offset = ", d_offset)

In [66]:
main()


s =  The target was hit.
d_offset =  -0.18367346938994444

In [ ]: