Gets the smallest bounding box that contains the line.
Gets the start point of the line.
Gets the length of the line.
Gets the end point of the line.
Gets the line's tangent vector. This vector is perpendicular to direction and is a unit vector.
If the environment's y-axis points upwards, it will be on the left side of the line if looking from -> to. If the environment's y-axis points downwards, it will be on the right side of the line if looking from -> to.
Creates a line from a set of coordinates.
A 2x2 array of values specifying the line's start and end point. Format: [[x1,y1],[x2,y2]]
.
Finds the closest point on the line and returns the parameter for the point.
The target to get closest to.
If true, the closest point will always be within the bounds of the line. If false, the line is treated as infinite.
The normalized parameter of the closest point. Entering the parameter into pointAt will return the closest point.
Checks whether another line has the same start and end points. Returns true if it does.
The line to compare against.
The amount that the points can differ and still be considered equal.
Lengthens the line by extending the end points. Returns the resulting line.
Calculates where the line intersects other geometry and returns the parameters for these points of intersection.
The geometry to intersect.
The parameters of the intersection points. The array is always sorted from the smallest to largest parameter. Entering the parameter into pointAt will return the intersection point.
Finds the point a normalized parameter along the line. Returns the point.
The parameter ranges from 0, which is the line's start (from), through to 1, which is the line's end (to). The mid point of the line is 0.5.
let line = new Line(new Point(0, 0), new Point(10, 0));
console.log(line.pointAt(0).toString());
// => (0,0)
console.log(line.pointAt(0.5).toString());
// => (5,0)
console.log(line.pointAt(1).toString());
// => (10,0)
The normalized parameter.
If true, the point will always be within the bounds of the line (u-values less than 0 will become 0 and values greater than 1 will become 1). If false, the line is treated as infinite.
Finds the point a given distance from the line's start (from) and returns the point.
The distance from the from point.
If true, the point will always be within the bounds of the line. If false, the line is treated as infinite.
Gets the line as a string in the format: [(x,y),(x,y)]
.
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 line by a transform matrix and returns the result.
import { Line, Point, Transform, Vector } from 'shapetypes';
// Create a line
const line = new Line(new Point(0,0), new Point(10,0));
console.log(line.toString());
// => [(0,0),(10,0)]
// Translate using a transform matrix
const matrix = Transform.translate(new Vector(5, 4));
const moved = line.transform(matrix);
console.log(moved.toString());
// => [(5,4),(15,4)]
// Translate using the direct method
const otherMoved = line.translate(5, 4);
console.log(otherMoved.toString());
// => [(5,4),(15,4)]
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 straight edge between two points.
Example
import { Line, Point, Transform, Vector } from 'shapetypes'; // Create a new line const line = new Line(new Point(1,1), new Point(4,5)); // Get properties of the line console.log(line.from.toString()); // => (1,1) console.log(line.to.toString()); // => (4,5) console.log(line.length); // => 5 const mid = line.pointAt(0.5); console.log(mid.toString()); // => (2.5,3) // Find closest point on the line const closest = line.closestPoint(new Point(5,5)); console.log(closest.toString()); // => (4,5) // Translate the line with a transform matrix const matrix = Transform.translate(new Vector(5, 0)); const moved = line.transform(matrix); console.log(moved.toString()); // => [(6,1),(9,5)]