std/geometry/ray3
std/geometry/src/ray3.trb
Ray3, the half-line in space, and the hit tests written against it: a pick, a line of sight, a shot, a shadow.
type Ray3
type Ray3<Scalar: Real = Float>
A half-line in space: where it starts and which way it points.
As in the plane, every hit test answers how far along the ray the hit is, measured in the length of direction,
and not the point: that is what a caller compares to find the nearest of several hits. Ray3.at turns a distance back
into a point.
Examples
const shot = Ray3 Vector3(0.0, 0.0, 0.0), Vector3(0.0, 0.0, 1.0)
print shot.hits(Sphere(Vector3(0.0, 0.0, 5.0), 1.0))
Pitfalls
- A
directionof zero has no hits at all, and every test answersNonefor it rather than panicking. - A ray that starts inside a shape answers
0.
Related
Ray2- the same in the plane.Triangle3.weightsOf- whatRay3.hitsTriangleuses to tell the plane from the face.
field origin
origin: Vector3<Scalar>
Where the ray starts.
field direction
direction: Vector3<Scalar>
Which way it points. The hit distances are measured in this vector's length.
fn towards
static fn towards(from: Vector3<Scalar>, to: Vector3<Scalar>): Ray3<Scalar>
The ray from one point towards another, with a direction of length one.
fn at
fn at(distance: Scalar): Vector3<Scalar>
The point that far along the ray. A negative distance reads backwards, behind the origin.
fn hits
fn hits(sphere: Sphere<Scalar>): Scalar?
How far along the ray the ball is first met, or None where the ray misses it. Inside answers zero.
fn hitsPlane
fn hitsPlane(plane: Plane<Scalar>): Scalar?
How far along the ray the plane is crossed, or None where the ray runs parallel to it or points away from it.
fn hitsBox
fn hitsBox(box: Box<Scalar>): Scalar?
How far along the ray the box is first met, or None where the ray misses it. This is the slab test in space.
fn hitsTriangle
fn hitsTriangle(triangle: Triangle3<Scalar>): Scalar?
How far along the ray the triangle is met, or None where the ray misses the face.
It crosses the triangle's plane first and then asks the triangle whether that point is inside it, which is the same two steps every ray-triangle test takes.