For Player 1: X1= xpos + 2*(turret_width)/3 Y1 = ypos + 3*(turret_width)/4 X2 =
ID: 3743924 • Letter: F
Question
For Player 1:
X1= xpos + 2*(turret_width)/3
Y1 = ypos + 3*(turret_width)/4
X2 = X1 + barrel_length*cos(theta)
X2 = Y1 + barrel_length*sin(theta)
Player 2:
X1 = xpos + turret_width/3
Y1 = ypos + 3*(turret_width)/4
X2 = X1 - barrel_length*cos(theta)
Y2 = Y1 + barrel_length*sin(theta)
Task : Writing the function
Once you have the equations for the gun barrel coordinates, write the function calc_barrel_pos
using the same ordering of arguments as above. This function MUST be saved with the filename
calc_barrel_pos.m. Use the argument player to determine which of the sets of equations to
use from Task 1 to calculate the gun barrel positions.
Explanation / Answer
Here's the function in C++ language:
pair<pair<double,double>,pair<double,double>> calc_barrel_pos(double xpos,double ypos,double turret_width,double barrel_length,double theta,double player)
{
double X1, X2, Y1, Y2;
pair<pair<double,double>,pair<double,double>> p;
if(player==1){
X1= xpos + 2*(turret_width)/3;
Y1 = ypos + 3*(turret_width)/4;
X2 = X1 + barrel_length*cos(theta);
X2 = Y1 + barrel_length*sin(theta);
}
if(player==-1){
X1 = xpos + turret_width/3;
Y1 = ypos + 3*(turret_width)/4;
X2 = X1 - barrel_length*cos(theta);
Y2 = Y1 + barrel_length*sin(theta);
}
p=make_pair(make_pair(X1,Y1),make_pair(X2,Y2));
return p;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.