From 431299a0007003d059085731069dbee05642683c Mon Sep 17 00:00:00 2001 From: davidrobert99 Date: Tue, 29 Mar 2022 12:06:46 +0100 Subject: [PATCH 1/2] update description project motion --- subjects/project_motion/README.md | 53 ++++++++++++++++++++----------- 1 file changed, 35 insertions(+), 18 deletions(-) diff --git a/subjects/project_motion/README.md b/subjects/project_motion/README.md index 28d69108c..81cff3270 100644 --- a/subjects/project_motion/README.md +++ b/subjects/project_motion/README.md @@ -2,16 +2,27 @@ ### 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 -essential for the projectile physics. (distance, velocity, height, time) +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 `throw_object` that will initialize the Object with a given velocity and height. -- The trait Iterator with the `.next()` in which,the next position of the object after 1 second, must be calculated. - It will return an `Option` with the Object or it will return `None` if the object already reached the floor. +- 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: + +$$ 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 @@ -24,17 +35,25 @@ You must implement : #[derive(Debug, Clone, PartialEq)] pub struct Object { - pub distance: f32, - pub velocity: f32, - pub height: f32, + 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 Object { - pub fn throw_object(velocity: f32, height: f32) -> Object {} +impl ThrowObject { + pub fn new(init_position: Object, init_velocity: Object) -> ThrowObject { + } } -impl Iterator for Object { +impl Iterator for ThrowObject { // next } @@ -48,8 +67,7 @@ Here is a program to test your function use project_motion::*; fn main() { - let mut obj = Object::throw_object(50.0, 150.0); - println!("{:?}", obj.next()); + 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()); @@ -62,10 +80,9 @@ And its output: ```console $ cargo run -Some(Object { distance: 50.0, velocity: 50.0, height: 145.1, time: 1.0 }) -Some(Object { distance: 100.0, velocity: 50.0, height: 125.5, time: 2.0 }) -Some(Object { distance: 150.0, velocity: 50.0, height: 81.4, time: 3.0 }) -Some(Object { distance: 200.0, velocity: 50.0, height: 3.0, time: 4.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(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 $ From 9c72b66e0693aff5e7a98b3ac5d0b078e81fa8e5 Mon Sep 17 00:00:00 2001 From: davidrobert99 Date: Tue, 10 May 2022 10:12:57 +0100 Subject: [PATCH 2/2] update project motion formula --- subjects/project_motion/README.md | 4 ++-- subjects/project_motion/position_formula.png | Bin 0 -> 3945 bytes subjects/project_motion/speed_formula.png | Bin 0 -> 2329 bytes 3 files changed, 2 insertions(+), 2 deletions(-) create mode 100644 subjects/project_motion/position_formula.png create mode 100644 subjects/project_motion/speed_formula.png diff --git a/subjects/project_motion/README.md b/subjects/project_motion/README.md index 81cff3270..d3c052ad2 100644 --- a/subjects/project_motion/README.md +++ b/subjects/project_motion/README.md @@ -17,11 +17,11 @@ You must implement : 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} $$ +![Position Formula](position_formula.png) and velocity (v) in the instant s of an object is given by: -$$ v(t) = v_{0} + a*t $$ +![Speed Formula](speed_formula.png) ### Notions diff --git a/subjects/project_motion/position_formula.png b/subjects/project_motion/position_formula.png new file mode 100644 index 0000000000000000000000000000000000000000..9757b3de0377cbe000508e2f82f33ac66831e3cd GIT binary patch literal 3945 zcma)9c{J4R`~DEwm&n+6l`Uk?*3iTxTedJH!tf?brjTu{O<60-7DCB3vSk}PS<4m% zja@><9ux6>-uM6CIlt$eSE5KFWg8F}iws{TzJppO<$U354O1 z5eIvFWx<3PCwC2~gNY&I%hxYo);BhUd3kLK0p;)8hqRDL+=PO%a+U9bKGahGa835& zMHRt>AG(Et)VfqiBs~qSh^Q$0S!`4k+zjI20GsY(th!Xne8wZ9{S2&6DqZ_vckkX6 zO59(snVD|zH+5ihN9dWg#LDH*&dye%2gsy`8Ui7BrYYq7`SYuf|GfjYxVZSu8$oDx zzB5*t@BZHE=zshD45uThpuyqcVT_31e9y}Z_4V}-RA?#v90|KjfM5U!yw-&mjEoq?cuU~Z@EOxiFz(Yc`m#9Rt*fjmg z-!Syw7S`6LCMIle-h4~umNHqlF1vk^ogN|fJc2Yer716OYW>1c;zd&+o2c+AX~O z&5xB6p5bsa6sq`+yqw(a8ZT0;x}=AP$Cr8g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mzQs^lN>c z3L05@leD$9Wl>;4p-_falp3n5sz8fc5zP@7!8x+9wZtpOsrc49zvX;$4jBD22HMF#~rvQlh`T$k|xdR8r4B_J9?A?Zu*3VHa$}Xoew-yUvF=EqQm7Rpb&MnweB7s z@d*h!!3PTG&%0%@Rw-OZB5j(21FfycI%B!to|Bg!7#!TJ9MH)qV5T^-79JY7yGv4d zOZ)r#Q&V{~H8r^!5^KC?LRY^PQY_9uvpPV<6ZzaSWmTIqy=9kr;H-DwMtic00=iCLd+47zhiL`O%+ixZWa^Nsb= z1>lQpWUW0tf5pkXJ-I)Ki%Qi#K0bDHa|`Fz zL2Fgr={l$UH$IgG)W$J*E83G&J6^xt_j^lA%gjvn(aFl+*KidMXI0N>0&kZuFt&kr qfir2dJOdX8^Bltm{r~T%c_57S&G(XW&qaXQ8M=PW1cBGP6Y)PM#Ayov literal 0 HcmV?d00001 diff --git a/subjects/project_motion/speed_formula.png b/subjects/project_motion/speed_formula.png new file mode 100644 index 0000000000000000000000000000000000000000..806c8141ba4e8a1e52c53ecaec9268c85cc1eee7 GIT binary patch literal 2329 zcmaJ@`#;ldAO8xon5A?x8_IGhMC4x1w2h6&{?~ zplCq%f#ZzckxSsTKf=~C5&+=u{wpGRT5uEqK>O{i&bm<;Kl2l8b0<+fLvJ>IeF@hX zi?8&4hKa6o(el;*U?qpnNJm~QRXyPu1cf~Dt1PjIcW|KTUz9_9A`Q6o!s6=VFF$Oy zYktXo|IX=4zIoEuwrRu!V}d_$L%Ctd_jUD-@x1rzwhg2C=DV`o*;!G=F=c8baiwRw^r5A=#B<|A;jhQ$6JB}XIuC9u3iK|c;Ot`i<%Hx$)*}1#B+uKWuos|*m zdiT!C#wI2@`gaV5rvtOx{!1qIv)L(ROuhlZ+OyjY!TiBspW zq&qr0kC~X{V_8Kb3j%@Q>({TLoGJxpK*ZiC5%YTUBJ%+}zwV{tBNTxAG4yQA_7h zKld8Q0H}g9!%!v9Ub?xUurRo8Tt-ac`*q`tjEwk%1dep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