Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- extern crate num;
- use num::traits::{RefNum, Num};
- /// cross product of vectors AB and AC
- pub fn cross2d<T>(a: &[T;2], b: &[T;2], c: &[T;2]) -> T where
- for<'a> &'a T: RefNum<T>,
- T: Num {
- return (&b[0]-&a[0]) * (&c[1]-&a[1]) - (&b[1]-&a[1]) * (&c[0]-&a[0]);
- }
- pub fn main() {
- let x = [0i32, 0i32];
- let y = [1i32, 0i32];
- let z = [0i32, 1i32];
- println!("{}", cross2d(&x, &y, &z))
- }
Add Comment
Please, Sign In to add comment