use super::{Quaternion, UnitQuaternion, Vector3};
use crate::defined::{float, PI};
fn get_direction(dir: Vector3, rotation: &UnitQuaternion) -> Vector3 {
let dir: UnitQuaternion = UnitQuaternion::from_quaternion(Quaternion::from_imag(dir));
(rotation * dir * rotation.conjugate()).imag().normalize()
}
pub trait Transducer: Send + Sync {
fn new(local_idx: usize, pos: Vector3, rot: UnitQuaternion) -> Self;
fn translate(&mut self, pos: Vector3) {
self.affine(pos, UnitQuaternion::identity());
}
fn rotate(&mut self, rot: UnitQuaternion) {
self.affine(Vector3::zeros(), rot);
}
fn affine(&mut self, pos: Vector3, rot: UnitQuaternion);
fn align_phase_at(&self, pos: Vector3, sound_speed: float) -> float {
(pos - self.position()).norm() * self.wavenumber(sound_speed)
}
fn position(&self) -> &Vector3;
fn rotation(&self) -> &UnitQuaternion;
fn local_idx(&self) -> usize;
fn x_direction(&self) -> Vector3 {
get_direction(Vector3::x(), self.rotation())
}
fn y_direction(&self) -> Vector3 {
get_direction(Vector3::y(), self.rotation())
}
fn z_direction(&self) -> Vector3 {
get_direction(Vector3::z(), self.rotation())
}
fn frequency(&self) -> float;
fn mod_delay(&self) -> u16;
fn set_mod_delay(&mut self, value: u16);
fn amp_filter(&self) -> float;
fn set_amp_filter(&mut self, value: float);
fn phase_filter(&self) -> float;
fn set_phase_filter(&mut self, value: float);
fn wavelength(&self, sound_speed: float) -> float {
sound_speed / self.frequency()
}
fn wavenumber(&self, sound_speed: float) -> float {
2.0 * PI * self.frequency() / sound_speed
}
fn cycle(&self) -> u16;
}