mirror of https://github.com/01-edu/public.git
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.
xpetit
46f4ddc49e
|
4 years ago | |
---|---|---|
.. | ||
README.md | 4 years ago |
README.md
vector_operations
Instructions
Define the structure ThreeDvector
that represents a 3 dimensional vector in (for convention in physics the vector are represented as ai + bj + ck where a, b, and c are real numbers and i, j and k represent the direction x,y and z respectively in the Cartesian plane there for we use the names i, j and k for the fields in the ThreeDVector structure
Look how the operations Addition and Subtraction work for a 3 dimensional vector and implement them by implementing the std::ops::Add and std::ops::Sub traits
Expected Functions and Structures
#[derive(Debug, Copy, Clone, PartialEq)]
pub struct ThreeDVector<T> {
pub i: T,
pub j: T,
pub k: T,
}
use std::ops::{Add, Sub};
impl Add for ThreeDVector<T> {
}
impl Sub for ThreeDVector<T> {
}
Usage
Here is a program to test your function.
use vector_operations::ThreeDVector;
fn main() {
let a = ThreeDVector { i: 3, j: 5, k: 2 };
let b = ThreeDVector { i: 2, j: 7, k: 4 };
println!("{:?}", a + b);
}
And its output
$ cargo run
ThreeDVector { i: 5, j: 12, k: 6 }
$