traffic-sim 0.1.1

A simple traffic simulation package focussed on performance and realism.
Documentation
1
2
3
4
5
6
7
8
9
10
use crate::math::{Point2d, Vector2d};
use cgmath::InnerSpace;

pub fn calc_direction(pos: Point2d, dir: Vector2d, new_pos: Point2d, radius: f64) -> Vector2d {
    let b = pos - radius * dir;
    let v = pos - b;
    let h = (v.magnitude2() - radius.powi(2)) / (2.0 * (radius + v.dot(dir)));
    let bp = b + h * dir;
    (new_pos - bp).normalize()
}