Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- use nalgebra::{Point3, Vector3};
- use nalgebra::{
- Point3,
- };
- use natural_constants::physics::magnetic_const_vac as u0;
- use std::f64::consts::PI;
- use crate::wire::{
- Wire
- };
- pub struct BiotSavartSolver {
- wires: Vec<Wire>
- }
- impl BiotSavartSolver {
- pub fn new() -> Self {
- Self {
- wires: vec![],
- }
- }
- pub fn from_wires(wires: Vec<Wire>) -> Self {
- Self {
- wires
- }
- }
- pub fn calculate_b(&self, points: Vec<Point3<f64>>, current: f64) -> Vec<f64> {
- let mut c = 0;
- points
- .iter()
- .map(|point| {
- self.calculate_b_at(point, current)
- })
- .collect::<_>()
- }
- fn calculate_b_at(&self, position: &Point3<f64>, current: f64) -> f64 {
- let integral = self.wires
- .iter()
- .flat_map(|segment| {
- let r = position - segment.position;
- let c = segment.direction.cross(&r);
- })
- .sum();
- u0 / (4.0 * PI) * current * integral
- }
- }
- pub struct Wire {
- pub segments: Vec<WireSegment>,
- }
- pub struct WireIterator<'w> {
- iter: &'w std::slice::Iter<'w, WireSegment>,
- }
- impl<'w> Iterator for WireIterator<'w> {
- type Item = &'w WireSegment;
- fn next(&mut self) -> Option<Self::Item> {
- self.iter.next()
- }
- }
- impl<'w> IntoIterator for Wire {
- type Item = &'w WireSegment;
- type IntoIter = WireIterator<'w>;
- fn into_iter(self) -> Self::IntoIter {
- WireIterator { iter: &self.segments }
- }
- }
- pub struct WireSegment {
- pub position: Point3<f64>,
- pub direction: Vector3<f64>,
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement