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.

51 lines
1.1 KiB

## vector_operations
### Instructions
Define the structure `ThreeDVector`, that represents a 3 dimensional vector.
In physics, these vectors are represented as `ai`, `bj` and `ck`. `a`, `b` and `c` are real numbers. `i`, `j` and `k` represent the direction in the Cartesian plane, along the axises `x`, `y` and `z` respectively. Therefore, we use the fields `i`, `j` and `k` in the structure.
Take a look how the operations `Addition` and `Subtraction` work for a 3 dimensional vector, and implement them by creating the `std::ops::Add` and `std::ops::Sub` traits.
### Expected Functions and Structures
```rust
#[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.
```rust
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
```console
$ cargo run
ThreeDVector { i: 5, j: 12, k: 6 }
$
```