Fire your cannons!
Description:
You are a pirate, and your captain wants you to help him figure out how far he can launch a cannonball.
The captain fires a cannonball from a cliff with a height of h
metres above sea level with a velocity of v
ms^-1 at an upward angle of theta
degrees to the ground into the ocean.
The captain now wants you to work out the cannonball's maximum height, and the horizontal distance the cannonball travelled.
Input = cannonball(theta,v,h)
theta
= the angle between the surface and the direction of the cannonball. It is parallel to the ground (in degrees)v
= initial velocity of the cannonball (in ms^-1)h
= initial height of the cannonball (in m)
Outputs = (maxh, distance)
maxh
= the maximum height of the cannonballdistance
= the horizontal distance the cannonball travels
Assume air resistance is negligible and that the gravitational constant g = 9.81
ms^-2. Assume that all inputs will be positive numbers less than 100.
Example: The captain fires his cannon from a height of 10m with a velocity of 40ms^-1 at an upward angle of 30° from the ground.
cannonball(30,40,10) = (30.387359836901116, 156.84578865761307)
- Maximum height = 30.4m
- Horizontal distance = 156.8m
Below is a fantastic sketch made by me visualizing this problem
Similar Kata:
Stats:
Created | Dec 21, 2024 |
Published | Dec 21, 2024 |
Warriors Trained | 34 |
Total Skips | 5 |
Total Code Submissions | 31 |
Total Times Completed | 17 |
Python Completions | 17 |
Total Stars | 5 |
% of votes with a positive feedback rating | 75% of 8 |
Total "Very Satisfied" Votes | 4 |
Total "Somewhat Satisfied" Votes | 4 |
Total "Not Satisfied" Votes | 0 |
Total Rank Assessments | 7 |
Average Assessed Rank | 7 kyu |
Highest Assessed Rank | 6 kyu |
Lowest Assessed Rank | 7 kyu |