You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 
davidrobert99 9c72b66e06 update project motion formula 2 years ago
..
README.md update project motion formula 2 years ago
position_formula.png update project motion formula 2 years ago
speed_formula.png update project motion formula 2 years ago

README.md

project_motion

Instructions

For this exercise, you will have to create a projectile motion.

Two structures will be provided. A structure called ThrowObject that will contain all the variables that are 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 :

  • 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 position and speed of the object must be calculated after 1 second. 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:

Position Formula

and velocity (v) in the instant s of an object is given by:

Speed Formula

Notions

Expected Function


#[derive(Debug, Clone, PartialEq)]
pub struct Object {
    pub x: f32,
    pub y: 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,
}

impl ThrowObject {
    pub fn new(init_position: Object, init_velocity: Object) -> ThrowObject {
    }
}

impl Iterator for ThrowObject {
  // next
}

Usage

Here is a program to test your function

use project_motion::*;

fn main() {
    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());
}

And its output:

$ cargo run
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(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(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 })
None
None
$