Table of Contents

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

position Vector3

The position in three dimensional space of the origin of the ray.

direction Vector3

The normalized direction of the ray.

Fields

Direction

The normalized direction in which the ray points.

public Vector3 Direction

Field Value

Vector3

Position

The position in three dimensional space where the ray starts.

public Vector3 Position

Field Value

Vector3

Methods

Create(Vector3, Vector3)

Create a new instance of the Ray struct.

public static Ray Create(Vector3 position, Vector3 direction)

Parameters

position Vector3

The position in three dimensional space of the origin of the ray.

direction Vector3

The normalized direction of the ray.

Returns

Ray

Equals(Ray)

Determines whether the specified Vector4 is equal to this instance.

public readonly bool Equals(Ray value)

Parameters

value Ray

The Vector4 to compare with this instance.

Returns

bool

true if the specified Vector4 is equal to this instance; otherwise, false.

Equals(ref Ray)

Determines whether the specified Vector4 is equal to this instance.

public readonly bool Equals(ref Ray value)

Parameters

value Ray

The Vector4 to compare with this instance.

Returns

bool

true if the specified Vector4 is equal to this instance; otherwise, false.

Equals(object?)

Determines whether the specified object is equal to this instance.

public override readonly bool Equals(object? obj)

Parameters

obj object

The object to compare with this instance.

Returns

bool

true if the specified object is equal to this instance; otherwise, false.

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

point Vector3

The 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

x int

X coordinate on 2d screen.

y int

Y coordinate on 2d screen.

viewport ViewportF

ViewportF.

worldViewProjection Matrix4x4

Transformation Matrix4x4.

Returns

Ray

Resulting Ray.

Intersects(BoundingBox)

Determines if there is an intersection between the current object and a BoundingBox.

public bool Intersects(BoundingBox box)

Parameters

box BoundingBox

The 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

box BoundingBox

The 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

box BoundingBox

The box to test.

point Vector3

When 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

box BoundingBox

The box to test.

distance float

When 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

sphere BoundingSphere

The 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

sphere BoundingSphere

The 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

sphere BoundingSphere

The sphere to test.

point Vector3

When 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

sphere BoundingSphere

The sphere to test.

distance float

When 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

ray Ray

The 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

ray Ray

The ray to test.

point Vector3

When 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

plane Plane

The 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

plane Plane

The plane to test.

point Vector3

When 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

plane Plane

The plane to test.

distance float

When 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

point Vector3

The 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

vertex1 Vector3

The first vertex of the triangle to test.

vertex2 Vector3

The second vertex of the triangle to test.

vertex3 Vector3

The 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

vertex1 Vector3

The first vertex of the triangle to test.

vertex2 Vector3

The second vertex of the triangle to test.

vertex3 Vector3

The third vertex of the triangle to test.

point Vector3

When 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

vertex1 Vector3

The first vertex of the triangle to test.

vertex2 Vector3

The second vertex of the triangle to test.

vertex3 Vector3

The third vertex of the triangle to test.

distance float

When 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

plane Plane

The plane

intersect Vector3

The point intersection

Returns

bool

PlaneIntersection(Vector3, Vector3, out Vector3)

Planes the intersection.

public bool PlaneIntersection(Vector3 planePosition, Vector3 planeNormal, out Vector3 intersect)

Parameters

planePosition Vector3

The plane position.

planeNormal Vector3

The plane normal.

intersect Vector3

The point intersection

Returns

bool

Reverse(Ray)

Reverse a ray in the opposite direction

public static Ray Reverse(Ray ray)

Parameters

ray Ray

The ray

Returns

Ray

A new ray in the reversed direction

ToString()

Returns a string that represents this instance.

public override readonly string ToString()

Returns

string

A string that represents this instance.

ToString(IFormatProvider)

Returns a string that represents this instance.

public readonly string ToString(IFormatProvider formatProvider)

Parameters

formatProvider IFormatProvider

The format provider.

Returns

string

A string that represents this instance.

ToString(string)

Returns a string that represents this instance.

public readonly string ToString(string format)

Parameters

format string

The format.

Returns

string

A string that represents this instance.

ToString(string?, IFormatProvider?)

Returns a string that represents this instance.

public readonly string ToString(string? format, IFormatProvider? formatProvider)

Parameters

format string

The format.

formatProvider IFormatProvider

The format provider.

Returns

string

A string that represents this instance.

Transform(in Matrix4x4)

Transform the ray using the specified transformation matrix.

public Ray Transform(in Matrix4x4 matrix)

Parameters

matrix Matrix4x4

Returns

Ray

Operators

operator ==(Ray, Ray)

Tests for equality between two objects.

public static bool operator ==(Ray left, Ray right)

Parameters

left Ray

The first value to compare.

right Ray

The second value to compare.

Returns

bool

true if left has the same value as right; otherwise, false.

operator !=(Ray, Ray)

Tests for inequality between two objects.

public static bool operator !=(Ray left, Ray right)

Parameters

left Ray

The first value to compare.

right Ray

The second value to compare.

Returns

bool

true if left has a different value than right; otherwise, false.