Write a program, Trajectory.java that animates a general ballistic trajectory i.
ID: 654173 • Letter: W
Question
Write a program, Trajectory.java that animates a general ballistic trajectory i.e., the ball is thrown at an angle. Assume the value of angle = 0.785 radians (45 degrees), initial coordinates = origin (0,0) and the speed of the ball = 60 m/s.
Things that you should know:
. g = - 9.8 m/s^2
. Acceleration in X direction = 0 m/s^2
. Acceleration in Y direction = g m/s^2
. Initial velocity in X direction = speed . cos(angle)
. Initial velocity in Y direction = speed . sin(angle)
. Distance in a direction at time t = Distance till time t -1 + V elocity in the direction x Delta time
. V elocity in a direction at time t = V elocity till time t -1 + Acceleration in the direction x Delta time
Explanation / Answer
public void main ( )
{
Number v0x = 0 ;
Number v0y = 0 ;
Number angleInDegrees = 0.785 ;
Number angleInRadians = 45 ;
world.setTheStage ( );
// Get and process user input
angleInDegrees .set( value , ( NumberDialog( question = Angle in degrees? ) ) );
duration = 0 seconds
angleInRadians .set( value , ( Math.toRadians( angleInDegrees ) ) );
duration = 0 seconds
v0x .set( value , ( ( 60 * ( Math.cos( angleInRadians ) ) ) ) );
v0y .set( value , ( ( 60 * ( Math.sin( angleInRadians ) ) ) ) );
// Fire the projectile
world.fireTheProjectile ( vx = v0x , vy = v0y );
}
public void setTheStage ( )
{
doInOrder
{
ground .setPointOfView( world );
duration = 0 seconds
safe .setPointOfView( world );
duration = 0 seconds
safe .turn( LEFT , 0.25 revolutions );
duration = 0 seconds
camera .setPointOfView( ground );
duration = 0 seconds
camera .turn( RIGHT , 0.5 revolutions );
duration = 0 seconds
camera .moveAwayFrom( target = safe , amount = 10 meters );
duration = 0 seconds
camera .move( UP , .0001 meters );
duration = 0 seconds
camera .move( BACKWARD , 10 meters );
duration = 0 seconds
camera .move( RIGHT , 5 meters );
duration = 0 seconds
}
}
public void fireTheProjectile ( Number vx, Number vy)
{
Number t = 0 ;
Number x = 0 ;
Number y = 0.01 ;
Number deltaT = 0.01 ;
Number tSquared = 0 ;
Number g = -9.8 ;
Number oldX = 0 ;
Number oldY = 0 ;
Number deltaX = 0 ;
Number deltaY = 0 ;
// Equations of motion
doInOrder
{
// ax = 0
// vx = v0x
// x = v0x * t
// ay = -g
// vy = v0y - g * t
// y = vy * t - 0.5 * g * t * t
// g = -9.8 feet per second per second
}
// Action
doInOrder
{
while ( ( y > 0 ) )
{
t .set( value , ( ( t + deltaT ) ) );
duration = 0 seconds
tSquared .set( value , ( ( t * t ) ) );
duration = 0 seconds
oldX .set( value , x );
duration = 0 seconds
x .set( value , ( ( t * vx ) ) );
duration = 0 seconds
deltaX .set( value , ( ( x - oldX ) ) );
duration = 0 seconds
oldY .set( value , y );
duration = 0 seconds
y .set( value , ( ( t * ( ( vy - ( ( tSquared * ( ( g * 0.5 ) ) ) ) ) ) ) ) );
duration = 0 seconds
deltaY .set( value , ( ( y - oldY ) ) );
duration = 0 seconds
doTogether
{
safe .move( FORWARD , deltaX meters );
style = BEGIN_AND_END_ABRUPTLY duration = .01 seconds
safe .move( UP , deltaY meters );
style = BEGIN_AND_END_ABRUPTLY duration = .01 seconds
}
}
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.