Guest User

Untitled

a guest
Jun 18th, 2018
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.63 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. /// cross product of vectors AB and AC
  14. pub fn cross<'a, 'b, 'c>(a: &'a [i32;2], b: &'b [i32;2], c: &'c [i32;2]) -> i32 {
  15.  
  16. return (&b[0]-&a[0]) * (&c[1]-&a[1]) - (&b[1]-&a[1]) * (&c[0]-&a[0]);
  17. }
  18.  
  19. pub fn main() {
  20. let x = [0i32, 0i32];
  21. let y = [1i32, 0i32];
  22. let z = [0i32, 1i32];
  23.  
  24. println!("{}", cross2d(&x, &y, &z));
  25. println!("{}", cross(&x, &y, &z));
  26. }
Add Comment
Please, Sign In to add comment