Gets the direction that the ray shoots. Is always a unit vector.
Gets the start point of the ray.
Finds the closest point on the ray and returns the parameter for the point.
The target to get closest to.
The extent of the ray. Specifies whether the ray is shooting both forward and backward, or only forward.
The parameter of the closest point. The parameter is the distance between from and the closest point. If the value is negative, it means the closest point is in the opposite direction to the direction vector. Entering the parameter into pointAt will return the closest point.
The ray to compare against.
The amount the point and vector can differ and still be considered equal.
Calculates where the ray intersects other geometry and returns the parameters for these points of intersection.
The geometry to intersect.
The extent of the ray. Specifies whether the ray is shooting both forward and backward, or only forward.
The parameters of the intersection points. The array is always sorted from the smallest to largest parameter. The parameter is the distance between from and the intersection point. If the value is negative, it means the point of intersection is in the opposite direction to the direction vector. Entering the parameter into pointAt will return the intersection point.
Gets the ray as a string in the format: [from,direction]
.
Translates the geometry from one coordinate system to another while keeping
the geometry in the same position. In other words, if the geometry is currently
described relative to planeFrom
, after changeBasis,
it will be in the same position but described relative to planeTo
.
The coordinate system the geometry is currently described relative to.
The coordinate system to describe the geometry relative to.
The geometry in the new coordinate system.
Rotates the geometry about (0,0).
Angle to rotate the geometry (in radians). The direction is counter-clockwise.
Rotates the geometry about a point.
Angle to rotate the geometry (in radians). If the environment's y-axis points upwards, the direction is counter-clockwise.
Point to pivot the geometry about.
Scales the geometry and returns the resized geometry. The geometry will be scaled about (0,0), meaning everything will shrink or expand away from this point.
Magnitude to scale in x- and y-direction. If less than 1, the object will shrink. If greater than 1, it will grow.
Scales the geometry and returns the resized geometry. The geometry will be scaled about (0,0), meaning everything will shrink or expand away from this point.
Magnitude to scale in x-direction. If less than 1, the object will shrink. If greater than 1, it will grow.
Magnitude to scale in y-direction. If less than 1, the object will shrink. If greater than 1, it will grow.
Scales the geometry about a point and returns the resized geometry.
Magnitude to scale in x-direction. If less than 1, the object will shrink. If greater than 1, it will grow.
Magnitude to scale in y-direction. If less than 1, the object will shrink. If greater than 1, it will grow.
Center of scaling. Everything will shrink or expand away from this point.
Transforms the ray by a Transform matrix and returns the result.
import { Point, Ray, Transform, Vector } from 'shapetypes';
// Create a new ray
const ray = new Ray(new Point(2,2), Vector.worldX());
console.log(ray.from.toString());
// => (2,2)
// Translate ray using a transform matrix
const matrix = Transform.translate(new Vector(3,4));
const moved = ray.transform(matrix);
console.log(moved.from.toString());
// => (5,6)
// Translate ray using the direct method
const otherMoved = ray.translate(new Vector(3,4));
console.log(otherMoved.from.toString());
// => (5,6)
Moves the geometry along a vector and returns the moved geometry. The translation is always linear.
The direction and distance to move the geometry.
Moves the geometry along a vector and returns the moved geometry. The translation is always linear.
The direction to move the geometry.
The distance to move the geometry.
Generated using TypeDoc
A line of infinite length. A ray has a start point (from) and a direction (direction) but no end point.
In general, the ray is considered infinite in both directions, meaning it shoots both forward and back. Certain methods accept RayRange as a parameter, which allows you to specify whether the ray should shoot in both directions or only forward.
Example
import { Point, Ray, Vector } from 'shapetypes'; // Create a new ray const ray = new Ray(new Point(3,4), new Vector(1,0)); // Get properties of the ray console.log(ray.from.toString()); // => (3,4) console.log(ray.direction.toString()); // => ⟨1,0⟩ // Get a point on the ray const p = ray.pointAt(5); console.log(p.toString()); // => (8,4) // Get parameter of intersection between point and ray console.log(ray.intersection(p)); // => [5] // Translate the ray const transformed = ray.translate(new Vector(3,4)); console.log(transformed.from.toString()); // => (6,8)