summaryrefslogtreecommitdiff
path: root/src/algebra/line.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/algebra/line.rs')
-rw-r--r--src/algebra/line.rs24
1 files changed, 24 insertions, 0 deletions
diff --git a/src/algebra/line.rs b/src/algebra/line.rs
new file mode 100644
index 0000000..45733b9
--- /dev/null
+++ b/src/algebra/line.rs
@@ -0,0 +1,24 @@
+use crate::{particle_system::Scalar, Point, Vector};
+
+pub struct Line {
+ pub point: Point,
+
+ /// Has to be normalized
+ pub vector: Vector,
+}
+
+impl Line {
+ pub fn new(point: Point, vector: Vector) -> Self {
+ Self {
+ point,
+ vector: vector.normalize(),
+ }
+ }
+
+ pub fn distance_to_point(&self, point: Point) -> Scalar {
+ let diff = point - self.point;
+ let lambda = diff.dot(&self.vector);
+
+ (diff - lambda * self.vector).norm()
+ }
+}