Struct Ray
- Namespace
- HelixToolkit.Maths
- Assembly
- HelixToolkit.Maths.dll
Represents a three dimensional line based on a point in space and a direction.
public struct Ray : IEquatable<Ray>, IFormattable
- Implements
- Inherited Members
- Extension Methods
Constructors
Ray(Vector3, Vector3)
Initializes a new instance of the Ray struct.
public Ray(Vector3 position, Vector3 direction)
Parameters
positionVector3The position in three dimensional space of the origin of the ray.
directionVector3The normalized direction of the ray.
Fields
Direction
The normalized direction in which the ray points.
public Vector3 Direction
Field Value
Position
The position in three dimensional space where the ray starts.
public Vector3 Position
Field Value
Methods
Create(Vector3, Vector3)
Create a new instance of the Ray struct.
public static Ray Create(Vector3 position, Vector3 direction)
Parameters
positionVector3The position in three dimensional space of the origin of the ray.
directionVector3The normalized direction of the ray.
Returns
Equals(Ray)
Determines whether the specified Vector4 is equal to this instance.
public readonly bool Equals(Ray value)
Parameters
Returns
Equals(ref Ray)
Determines whether the specified Vector4 is equal to this instance.
public readonly bool Equals(ref Ray value)
Parameters
Returns
Equals(object?)
Determines whether the specified object is equal to this instance.
public override readonly bool Equals(object? obj)
Parameters
Returns
GetHashCode()
Returns a hash code for this instance.
public override readonly int GetHashCode()
Returns
- int
A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table.
GetNearest(Vector3)
Gets the point on the ray that is nearest the specified point.
public Vector3 GetNearest(Vector3 point)
Parameters
pointVector3The point.
Returns
- Vector3
The nearest point on the ray.
GetPickRay(int, int, ViewportF, Matrix4x4)
Calculates a world space Ray from 2d screen coordinates.
public static Ray GetPickRay(int x, int y, ViewportF viewport, Matrix4x4 worldViewProjection)
Parameters
xintX coordinate on 2d screen.
yintY coordinate on 2d screen.
viewportViewportFworldViewProjectionMatrix4x4Transformation Matrix4x4.
Returns
Intersects(BoundingBox)
Determines if there is an intersection between the current object and a BoundingBox.
public bool Intersects(BoundingBox box)
Parameters
boxBoundingBoxThe box to test.
Returns
- bool
Whether the two objects intersected.
Intersects(ref BoundingBox)
Determines if there is an intersection between the current object and a BoundingBox.
public bool Intersects(ref BoundingBox box)
Parameters
boxBoundingBoxThe box to test.
Returns
- bool
Whether the two objects intersected.
Intersects(ref BoundingBox, out Vector3)
Determines if there is an intersection between the current object and a BoundingBox.
public bool Intersects(ref BoundingBox box, out Vector3 point)
Parameters
boxBoundingBoxThe box to test.
pointVector3When the method completes, contains the point of intersection, or Zero if there was no intersection.
Returns
- bool
Whether the two objects intersected.
Intersects(ref BoundingBox, out float)
Determines if there is an intersection between the current object and a BoundingBox.
public bool Intersects(ref BoundingBox box, out float distance)
Parameters
boxBoundingBoxThe box to test.
distancefloatWhen the method completes, contains the distance of the intersection, or 0 if there was no intersection.
Returns
- bool
Whether the two objects intersected.
Intersects(BoundingSphere)
Determines if there is an intersection between the current object and a BoundingSphere.
public bool Intersects(BoundingSphere sphere)
Parameters
sphereBoundingSphereThe sphere to test.
Returns
- bool
Whether the two objects intersected.
Intersects(ref BoundingSphere)
Determines if there is an intersection between the current object and a BoundingSphere.
public bool Intersects(ref BoundingSphere sphere)
Parameters
sphereBoundingSphereThe sphere to test.
Returns
- bool
Whether the two objects intersected.
Intersects(ref BoundingSphere, out Vector3)
Determines if there is an intersection between the current object and a BoundingSphere.
public bool Intersects(ref BoundingSphere sphere, out Vector3 point)
Parameters
sphereBoundingSphereThe sphere to test.
pointVector3When the method completes, contains the point of intersection, or Zero if there was no intersection.
Returns
- bool
Whether the two objects intersected.
Intersects(ref BoundingSphere, out float)
Determines if there is an intersection between the current object and a BoundingSphere.
public bool Intersects(ref BoundingSphere sphere, out float distance)
Parameters
sphereBoundingSphereThe sphere to test.
distancefloatWhen the method completes, contains the distance of the intersection, or 0 if there was no intersection.
Returns
- bool
Whether the two objects intersected.
Intersects(ref Ray)
Determines if there is an intersection between the current object and a Ray.
public bool Intersects(ref Ray ray)
Parameters
rayRayThe ray to test.
Returns
- bool
Whether the two objects intersected.
Intersects(ref Ray, out Vector3)
Determines if there is an intersection between the current object and a Ray.
public bool Intersects(ref Ray ray, out Vector3 point)
Parameters
rayRayThe ray to test.
pointVector3When the method completes, contains the point of intersection, or Zero if there was no intersection.
Returns
- bool
Whether the two objects intersected.
Intersects(ref Plane)
Determines if there is an intersection between the current object and a Plane.
public bool Intersects(ref Plane plane)
Parameters
planePlaneThe plane to test
Returns
- bool
Whether the two objects intersected.
Intersects(ref Plane, out Vector3)
Determines if there is an intersection between the current object and a Plane.
public bool Intersects(ref Plane plane, out Vector3 point)
Parameters
planePlaneThe plane to test.
pointVector3When the method completes, contains the point of intersection, or Zero if there was no intersection.
Returns
- bool
Whether the two objects intersected.
Intersects(ref Plane, out float)
Determines if there is an intersection between the current object and a Plane.
public bool Intersects(ref Plane plane, out float distance)
Parameters
planePlaneThe plane to test.
distancefloatWhen the method completes, contains the distance of the intersection, or 0 if there was no intersection.
Returns
- bool
Whether the two objects intersected.
Intersects(ref Vector3)
Determines if there is an intersection between the current object and a point.
public bool Intersects(ref Vector3 point)
Parameters
pointVector3The point to test.
Returns
- bool
Whether the two objects intersected.
Intersects(ref Vector3, ref Vector3, ref Vector3)
Determines if there is an intersection between the current object and a triangle.
public bool Intersects(ref Vector3 vertex1, ref Vector3 vertex2, ref Vector3 vertex3)
Parameters
vertex1Vector3The first vertex of the triangle to test.
vertex2Vector3The second vertex of the triangle to test.
vertex3Vector3The third vertex of the triangle to test.
Returns
- bool
Whether the two objects intersected.
Intersects(ref Vector3, ref Vector3, ref Vector3, out Vector3)
Determines if there is an intersection between the current object and a triangle.
public bool Intersects(ref Vector3 vertex1, ref Vector3 vertex2, ref Vector3 vertex3, out Vector3 point)
Parameters
vertex1Vector3The first vertex of the triangle to test.
vertex2Vector3The second vertex of the triangle to test.
vertex3Vector3The third vertex of the triangle to test.
pointVector3When the method completes, contains the point of intersection, or Zero if there was no intersection.
Returns
- bool
Whether the two objects intersected.
Intersects(ref Vector3, ref Vector3, ref Vector3, out float)
Determines if there is an intersection between the current object and a triangle.
public bool Intersects(ref Vector3 vertex1, ref Vector3 vertex2, ref Vector3 vertex3, out float distance)
Parameters
vertex1Vector3The first vertex of the triangle to test.
vertex2Vector3The second vertex of the triangle to test.
vertex3Vector3The third vertex of the triangle to test.
distancefloatWhen the method completes, contains the distance of the intersection, or 0 if there was no intersection.
Returns
- bool
Whether the two objects intersected.
PlaneIntersection(Plane, out Vector3)
Planes the intersection.
public bool PlaneIntersection(Plane plane, out Vector3 intersect)
Parameters
Returns
PlaneIntersection(Vector3, Vector3, out Vector3)
Planes the intersection.
public bool PlaneIntersection(Vector3 planePosition, Vector3 planeNormal, out Vector3 intersect)
Parameters
planePositionVector3The plane position.
planeNormalVector3The plane normal.
intersectVector3The point intersection
Returns
Reverse(Ray)
Reverse a ray in the opposite direction
public static Ray Reverse(Ray ray)
Parameters
rayRayThe ray
Returns
- Ray
A new ray in the reversed direction
ToString()
Returns a string that represents this instance.
public override readonly string ToString()
Returns
ToString(IFormatProvider)
Returns a string that represents this instance.
public readonly string ToString(IFormatProvider formatProvider)
Parameters
formatProviderIFormatProviderThe format provider.
Returns
ToString(string)
Returns a string that represents this instance.
public readonly string ToString(string format)
Parameters
formatstringThe format.
Returns
ToString(string?, IFormatProvider?)
Returns a string that represents this instance.
public readonly string ToString(string? format, IFormatProvider? formatProvider)
Parameters
formatstringThe format.
formatProviderIFormatProviderThe format provider.
Returns
Transform(in Matrix4x4)
Transform the ray using the specified transformation matrix.
public Ray Transform(in Matrix4x4 matrix)
Parameters
matrixMatrix4x4
Returns
Operators
operator ==(Ray, Ray)
Tests for equality between two objects.
public static bool operator ==(Ray left, Ray right)
Parameters
Returns
- bool
trueiflefthas the same value asright; otherwise,false.
operator !=(Ray, Ray)
Tests for inequality between two objects.
public static bool operator !=(Ray left, Ray right)
Parameters
Returns
- bool
trueiflefthas a different value thanright; otherwise,false.