Skip to content

Commit

Permalink
Add Plane::project_vector
Browse files Browse the repository at this point in the history
  • Loading branch information
hannobraun committed Sep 30, 2022
1 parent 1f7be33 commit d3f6b6b
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions crates/fj-math/src/plane.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,14 @@ impl Plane {
self.normal().dot(vector) == Scalar::ZERO
}

/// Project a vector into the plane
pub fn project_vector(&self, vector: &Vector<3>) -> Vector<2> {
Vector::from([
self.u().scalar_projection_onto(vector),
self.v().scalar_projection_onto(vector),
])
}

/// Project a line into the plane
pub fn project_line(&self, line: &Line<3>) -> Line<2> {
let line_origin_relative_to_plane = line.origin() - self.origin();
Expand All @@ -73,10 +81,7 @@ impl Plane {
]),
};

let line_direction_in_plane = Vector::from([
self.u().scalar_projection_onto(&line.direction()),
self.v().scalar_projection_onto(&line.direction()),
]);
let line_direction_in_plane = self.project_vector(&line.direction());

Line::from_origin_and_direction(
line_origin_in_plane,
Expand Down

0 comments on commit d3f6b6b

Please sign in to comment.