|
|
@@ -1,3 +1,67 @@
|
|
|
-fn main() {
|
|
|
+#![allow(dead_code)]
|
|
|
+use rand::Rng;
|
|
|
+
|
|
|
+
|
|
|
+//Constants
|
|
|
+const N : usize = 5;
|
|
|
+
|
|
|
+fn main(){
|
|
|
println!("Hello, world!");
|
|
|
+ println!("{:?}", create_grid(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)]
|
|
|
+struct GridPoint {
|
|
|
+ coords: Vec<f64>,
|
|
|
+}
|
|
|
+
|
|
|
+impl GridPoint {
|
|
|
+ fn new(dimensions: usize) -> Self {
|
|
|
+ GridPoint {
|
|
|
+ coords: vec![0.0; dimensions],
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+fn create_grid_point() -> 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
|
|
|
+}
|
|
|
+
|
|
|
+fn create_grid(n: usize) -> Vec<GridPoint> {
|
|
|
+ let mut points = Vec::new();
|
|
|
+ for _ in 0..n {
|
|
|
+ points.push(create_grid_point());
|
|
|
+ }
|
|
|
+ points
|
|
|
+}
|
|
|
+
|
|
|
+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()
|
|
|
+}
|
|
|
+
|