Browse Source

update description project motion

pull/1039/head
davidrobert99 2 years ago
parent
commit
431299a000
  1. 53
      subjects/project_motion/README.md

53
subjects/project_motion/README.md

@ -2,16 +2,27 @@
### Instructions ### Instructions
For this exercise you will have to create a [projectile motion](https://cimg2.ck12.org/datastreams/f-d%3Abb024be6673110b31e78b46819e792adaed8dc661e082a61f0a6d64e%2BIMAGE%2BIMAGE.1). For this exercise, you will have to create a [projectile motion](https://cimg2.ck12.org/datastreams/f-d%3Abb024be6673110b31e78b46819e792adaed8dc661e082a61f0a6d64e%2BIMAGE%2BIMAGE.1).
A structure called `Object` will be provided which will have all variables that are Two structures will be provided. A structure called `ThrowObject` that will contain all the variables that are
essential for the projectile physics. (distance, velocity, height, time) essential for the projectile physics (initial position, initial velocity, current position, current velocity and time).
A structure called `Object` which will have the corresponding values of X and Y of the initial position, the initial velocity, the current position and the current velocity.
You must implement : You must implement :
- A function `throw_object` that will initialize the Object with a given velocity and height. - A function `new` that will initialize the ThrowObject with a given initial position and an initial velocity.
- The trait Iterator with the `.next()` in which,the next position of the object after 1 second, must be calculated. - The trait Iterator with the `.next()` in which the position and speed of the object must be calculated after 1 second.
It will return an `Option` with the Object or it will return `None` if the object already reached the floor. It will return an `Option` with the ThrowObject, or it will return `None` if the ThrowObject has already reached the floor.
Consider the value of gravity is 9.8m/(s*s) and that the position (p) in the instant s of an object is given by:
$$ p(t) = p_{0} + v_{0}*t +\frac{1}{2}* a*t^{2} $$
and velocity (v) in the instant s of an object is given by:
$$ v(t) = v_{0} + a*t $$
### Notions ### Notions
@ -24,17 +35,25 @@ You must implement :
#[derive(Debug, Clone, PartialEq)] #[derive(Debug, Clone, PartialEq)]
pub struct Object { pub struct Object {
pub distance: f32, pub x: f32,
pub velocity: f32, pub y: f32,
pub height: f32, }
#[derive(Debug, Clone, PartialEq)]
pub struct ThrowObject {
pub init_position: Object,
pub init_velocity: Object,
pub actual_position: Object,
pub actual_velocity: Object,
pub time: f32, pub time: f32,
} }
impl Object { impl ThrowObject {
pub fn throw_object(velocity: f32, height: f32) -> Object {} pub fn new(init_position: Object, init_velocity: Object) -> ThrowObject {
}
} }
impl Iterator for Object { impl Iterator for ThrowObject {
// next // next
} }
@ -48,8 +67,7 @@ Here is a program to test your function
use project_motion::*; use project_motion::*;
fn main() { fn main() {
let mut obj = Object::throw_object(50.0, 150.0); let mut obj = ThrowObject::new(Object { x: 50.0, y: 50.0 }, Object { x: 0.0, y: 0.0 });
println!("{:?}", obj.next());
println!("{:?}", obj.next()); println!("{:?}", obj.next());
println!("{:?}", obj.next()); println!("{:?}", obj.next());
println!("{:?}", obj.next()); println!("{:?}", obj.next());
@ -62,10 +80,9 @@ And its output:
```console ```console
$ cargo run $ cargo run
Some(Object { distance: 50.0, velocity: 50.0, height: 145.1, time: 1.0 }) Some(ThrowObject { init_position: Object { x: 50.0, y: 50.0 }, init_velocity: Object { x: 0.0, y: 0.0 }, actual_position: Object { x: 50.0, y: 45.1 }, actual_velocity: Object { x: 0.0, y: -9.8 }, time: 1.0 })
Some(Object { distance: 100.0, velocity: 50.0, height: 125.5, time: 2.0 }) Some(ThrowObject { init_position: Object { x: 50.0, y: 50.0 }, init_velocity: Object { x: 0.0, y: 0.0 }, actual_position: Object { x: 50.0, y: 30.4 }, actual_velocity: Object { x: 0.0, y: -19.6 }, time: 2.0 })
Some(Object { distance: 150.0, velocity: 50.0, height: 81.4, time: 3.0 }) Some(ThrowObject { init_position: Object { x: 50.0, y: 50.0 }, init_velocity: Object { x: 0.0, y: 0.0 }, actual_position: Object { x: 50.0, y: 5.9 }, actual_velocity: Object { x: 0.0, y: -29.4 }, time: 3.0 })
Some(Object { distance: 200.0, velocity: 50.0, height: 3.0, time: 4.0 })
None None
None None
$ $

Loading…
Cancel
Save