Guest User

Untitled

a guest
Jun 18th, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.40 KB | None | 0 0
  1. extern crate num;
  2. use num::traits::{RefNum, Num};
  3.  
  4.  
  5. /// cross product of vectors AB and AC
  6. pub fn cross2d<T>(a: &[T;2], b: &[T;2], c: &[T;2]) -> T where
  7. for<'a> &'a T: RefNum<T>,
  8. T: Num {
  9.  
  10. return (&b[0]-&a[0]) * (&c[1]-&a[1]) - (&b[1]-&a[1]) * (&c[0]-&a[0]);
  11. }
  12.  
  13. pub fn main() {
  14. let x = [0i32, 0i32];
  15. let y = [1i32, 0i32];
  16. let z = [0i32, 1i32];
  17.  
  18. println!("{}", cross2d(&x, &y, &z))
  19. }
Add Comment
Please, Sign In to add comment