| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364 |
- #![allow(dead_code)]
- use rand::Rng;
- mod smoothstep;
- //Constants
- const N : usize = 5;
- fn main(){
- println!("Hello, world!");
- //println!("{:?}", create_grid_with_vectors(10));
- }
- fn dotproduct(a:Vec<f64>, b:Vec<f64>)->f64{
- let mut sum = 0.0;
- for i in 0..a.len(){
- sum += a[i]*b[i];
- }
- sum
- }
- fn crossproduct(a:Vec<f64>, b:Vec<f64>)-> Vec<f64>{
- let mut c = vec![0.0; 3];
- c[0] = a[1]*b[2] - a[2]*b[1];
- c[1] = a[2]*b[0] - a[0]*b[2];
- c[2] = a[0]*b[1] - a[1]*b[0];
- c
- }
- use std::fmt::Debug;
- #[derive(Debug, Clone)]
- struct GridPoint {
- coords: Vec<f64>,
- }
- impl GridPoint {
- fn new(dimensions: usize) -> Self {
- GridPoint {
- coords: vec![0.0; dimensions],
- }
- }
- }
- //Create a random vector for a point of the grid
- fn create_grid_vector() -> GridPoint {
- let mut rng = rand::thread_rng();
- let mut point = GridPoint::new(N);
- for i in 0..N {
- point.coords[i] = rng.gen_range(-1.0..=1.0);
- }
- point
- }
- //Create a grid of points in N dimensions between -1 and 1 for the N dimensions
- //
- fn distance(a: &GridPoint, b: &GridPoint) -> f64 {
- let mut sum = 0.0;
- for i in 0..N {
- sum += (a.coords[i] - b.coords[i]).powi(2);
- }
- sum.sqrt()
- }
|