atomecs/laser/
frame.rs

1//! Reference Frame orthogonal to the beam
2
3extern crate nalgebra;
4extern crate rayon;
5extern crate specs;
6use nalgebra::Vector3;
7use specs::Component;
8use specs::VecStorage;
9
10/// A component that stores the orthonormal basis vectors of a reference frame orthogonal to the beam.
11#[derive(Clone, Copy)]
12pub struct Frame {
13    pub x_vector: Vector3<f64>,
14    pub y_vector: Vector3<f64>,
15}
16impl Component for Frame {
17    type Storage = VecStorage<Self>;
18}
19
20impl Frame {
21    pub fn from_direction(beam_direction: Vector3<f64>, x_vector: Vector3<f64>) -> Self {
22        let scalar_product: f64 = Vector3::dot(&beam_direction, &x_vector);
23        if scalar_product != 0.0 {
24            panic!("You entered non-orthogonal vectors!");
25        }
26        if beam_direction.norm() * x_vector.norm() == 0.0 {
27            panic!("At least one of the entered vectors is zero!");
28        }
29        let orth_vector: Vector3<f64> = Vector3::cross(&beam_direction, &x_vector).normalize();
30        let x_vector = x_vector.normalize();
31        Frame {
32            x_vector,
33            y_vector: orth_vector,
34        }
35    }
36}