main.rs 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. #![allow(dead_code)]
  2. use rand::Rng;
  3. mod smoothstep;
  4. //Constants
  5. const N : usize = 5;
  6. fn main(){
  7. println!("Hello, world!");
  8. //println!("{:?}", create_grid_with_vectors(10));
  9. }
  10. fn dotproduct(a:Vec<f64>, b:Vec<f64>)->f64{
  11. let mut sum = 0.0;
  12. for i in 0..a.len(){
  13. sum += a[i]*b[i];
  14. }
  15. sum
  16. }
  17. fn crossproduct(a:Vec<f64>, b:Vec<f64>)-> Vec<f64>{
  18. let mut c = vec![0.0; 3];
  19. c[0] = a[1]*b[2] - a[2]*b[1];
  20. c[1] = a[2]*b[0] - a[0]*b[2];
  21. c[2] = a[0]*b[1] - a[1]*b[0];
  22. c
  23. }
  24. use std::fmt::Debug;
  25. #[derive(Debug, Clone)]
  26. struct GridPoint {
  27. coords: Vec<f64>,
  28. }
  29. impl GridPoint {
  30. fn new(dimensions: usize) -> Self {
  31. GridPoint {
  32. coords: vec![0.0; dimensions],
  33. }
  34. }
  35. }
  36. //Create a random vector for a point of the grid
  37. fn create_grid_vector() -> GridPoint {
  38. let mut rng = rand::thread_rng();
  39. let mut point = GridPoint::new(N);
  40. for i in 0..N {
  41. point.coords[i] = rng.gen_range(-1.0..=1.0);
  42. }
  43. point
  44. }
  45. //Create a grid of points in N dimensions between -1 and 1 for the N dimensions
  46. //
  47. fn distance(a: &GridPoint, b: &GridPoint) -> f64 {
  48. let mut sum = 0.0;
  49. for i in 0..N {
  50. sum += (a.coords[i] - b.coords[i]).powi(2);
  51. }
  52. sum.sqrt()
  53. }