pub struct Ray3 { /* private fields */ }
Expand description
A 3D ray that holds an origin and direction both as 3D vectors
Implementations§
Source§impl Ray3
Constructors
impl Ray3
Constructors
Sourcepub fn new(origin: Vector3, direction: Vector3) -> Self
pub fn new(origin: Vector3, direction: Vector3) -> Self
Creates a new 3D ray
- origin: The origin of the ray
- direction: The direction the ray is pointing at
Returns: Returns a new 3D ray
§Examples
let ray = Ray3::new(Vector3::one(), Vector3::forward());
assert_eq!(Vector3::one(), ray.origin());
assert_eq!(Vector3::forward(), ray.direction());
Source§impl Ray3
Properties
impl Ray3
Properties
Sourcepub fn origin(&self) -> Vector3
pub fn origin(&self) -> Vector3
Gets the origin of the ray as a 3D vector
Returns: Returns the origin of the ray
§Examples
let ray = Ray3::new(Vector3::one(), Vector3::forward());
assert_eq!(Vector3::one(), ray.origin());
Sourcepub fn set_origin(&mut self, value: Vector3)
pub fn set_origin(&mut self, value: Vector3)
Sets the origin of the ray
- value: The value to set the origin to
§Examples
let mut ray = Ray3::new(Vector3::one(), Vector3::forward());
ray.set_origin(Vector3::forward());
assert_eq!(Vector3::forward(), ray.origin());
Sourcepub fn direction(&self) -> Vector3
pub fn direction(&self) -> Vector3
Gets the direction of the ray as a 3D vector
Returns: Returns the direction of the ray
§Examples
let ray = Ray3::new(Vector3::one(), Vector3::forward());
assert_eq!(Vector3::forward(), ray.direction());
Sourcepub fn set_direction(&mut self, value: Vector3)
pub fn set_direction(&mut self, value: Vector3)
Sets the direction of the ray
- value: The value to set the direction to
§Examples
let mut ray = Ray3::new(Vector3::one(), Vector3::forward());
ray.set_direction(Vector3::one());
assert_eq!(Vector3::one(), ray.direction());
Source§impl Ray3
Public Methods
impl Ray3
Public Methods
Sourcepub fn get_point(self, distance: f32) -> Vector3
pub fn get_point(self, distance: f32) -> Vector3
Gets the point on the ray from the given distance
- distance: The distance from the ray to get the point from
Returns: Returns a 3D point from the given distance from the ray
§Examples
let ray = Ray3::new(Vector3::one(), Vector3::forward());
let point = ray.get_point(4.3);
assert_eq!(Vector3::new(1.0, 1.0, 5.3), point);
Sourcepub fn closest_point(self, point: Vector3) -> Vector3
pub fn closest_point(self, point: Vector3) -> Vector3
Gets the closest point on the ray from the given point
- point: The point to get the closest point from
Returns: Returns the closest point from the given point
§Examples
let ray = Ray3::new(Vector3::one(), Vector3::forward());
let point = ray.closest_point(Vector3::down());
assert_eq!(Vector3::new(1.0, 1.0, 0.0), point);
Sourcepub fn distance(self, point: Vector3) -> f32
pub fn distance(self, point: Vector3) -> f32
Gets the distance between the point and the ray’s line
- point: The point to check the distance from
Returns: Returns the distance between the point and the ray’s line
§Examples
let ray = Ray3::new(Vector3::forward(), Vector3::forward());
let distance = ray.distance(Vector3::down());
assert_eq!(1.0, distance);
let ray = Ray3::new(Vector3::one(), Vector3::forward());
let distance = ray.distance(Vector3::down());
assert_eq!(2.236068, distance);
Trait Implementations§
Source§impl DivAssign<f32> for Ray3
impl DivAssign<f32> for Ray3
Source§fn div_assign(&mut self, rhs: f32)
fn div_assign(&mut self, rhs: f32)
Performs the
/=
operation. Read moreSource§impl DivAssign<i32> for Ray3
impl DivAssign<i32> for Ray3
Source§fn div_assign(&mut self, rhs: i32)
fn div_assign(&mut self, rhs: i32)
Performs the
/=
operation. Read moreSource§impl MulAssign<f32> for Ray3
impl MulAssign<f32> for Ray3
Source§fn mul_assign(&mut self, rhs: f32)
fn mul_assign(&mut self, rhs: f32)
Performs the
*=
operation. Read moreSource§impl MulAssign<i32> for Ray3
impl MulAssign<i32> for Ray3
Source§fn mul_assign(&mut self, rhs: i32)
fn mul_assign(&mut self, rhs: i32)
Performs the
*=
operation. Read moreimpl Copy for Ray3
impl Eq for Ray3
impl Send for Ray3
impl Sync for Ray3
Auto Trait Implementations§
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more