-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Convert z_slice to generalized slice
- Loading branch information
Showing
17 changed files
with
144 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
use nalgebra::{UnitVector3, Vector3}; | ||
|
||
#[derive(Debug)] | ||
pub enum Axis { | ||
X, | ||
Y, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
use nalgebra::Vector3; | ||
|
||
use super::Plane; | ||
|
||
#[derive(Debug)] | ||
pub struct Line { | ||
pub a: Vector3<f32>, | ||
pub b: Vector3<f32>, | ||
} | ||
|
||
impl Line { | ||
pub fn new(a: Vector3<f32>, b: Vector3<f32>) -> Self { | ||
Self { a, b } | ||
} | ||
|
||
/// Returns the intersection of this line with a plane (if any). | ||
pub fn intersect_plane(&self, plane: &Plane) -> Option<Vector3<f32>> { | ||
Self::intersect_plane_raw(&self.a, &self.b, plane) | ||
} | ||
|
||
/// Returns the intersection of a line with start and endpoints on a plane (if any). | ||
pub fn intersect_plane_raw( | ||
a: &Vector3<f32>, | ||
b: &Vector3<f32>, | ||
plane: &Plane, | ||
) -> Option<Vector3<f32>> { | ||
let s = (a - b).dot(&plane.normal); | ||
|
||
// => line and plane parallel | ||
if s == 0.0 { | ||
return None; | ||
} | ||
|
||
let t = (plane.origin - b).dot(&plane.normal) / s; | ||
|
||
// => point not on line | ||
if !(0.0..1.0).contains(&t) { | ||
return None; | ||
} | ||
|
||
Some(b.lerp(a, t)) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
use nalgebra::Vector3; | ||
|
||
#[derive(Debug)] | ||
pub struct Sphere { | ||
pub origin: Vector3<f32>, | ||
pub radius: f32, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.