Line

A Line is a straight one-dimensional figure that extends infinitely in both directions. It is defined by two points.

Constructor

new Line(start, end)

Creates a new Line object from two points.

Parameters:
NameTypeDescription
startPoint2D
endPoint2D

Classes

Line

Members

end

The ending point of the line as Point2D.

end

The ending point of the line as Point2D.

length

Returns the length of the line.

start

The starting point of the line as Point2D.

start

The starting point of the line as Point2D.

vector_object_builder

Gets a VectorObjectBuilder with the line's points.

Methods

contains(point) → {boolean}

Returns whether the line contains a given Point2D.

Parameters:
NameTypeDescription
pointPoint2D

The point to check if it is contained.

Returns:

Whether the line contains the given point.

Type: 
boolean

distance_to_point(point) → {number}

Returns the distance from the line to a given Point2D.

Parameters:
NameTypeDescription
pointPoint2D

The point to calculate the distance to.

Returns:

The distance from the line to the given point.

Type: 
number

intersection(other) → {Point2D|undefined}

Returns the intersection Point2D of the line with another line, if it exists.

Parameters:
NameTypeDescription
otherLine

The other line to intersect with.

Returns:

The intersection point of the two lines if it exists.

Type: 
Point2D | undefined

midpoint() → {Point2D}

Returns the midpoint of the line as a Point2D.

Returns:

The midpoint of the line.

Type: 
Point2D

normal_slope() → {number}

Returns the normal slope of the line.

Returns:

The normal slope of the line.

Type: 
number

perpendicular_line(point) → {Line}

Returns the perpendicular line of the line at a given Point2D.

Parameters:
NameTypeDescription
pointPoint2D

The point to create the perpendicular line at.

Returns:

The perpendicular line of the line at the given point.

Type: 
Line

slope() → {number}

Returns the slope of the line.

Returns:

The slope of the line.

Type: 
number

with_tip_at_the_end(tip_shape) → {VectorObjectBuilder}

Creates a VectorObjectBuilder with the line's points and a tip at the end.

Parameters:
NameTypeDescription
tip_shapeVectorObjectBuilder

The shape of the tip. The shape must be pointing to the right and centered to (0, 0), this function will rotate and move it to the correct angle.

Returns:

A VectorObjectBuilder with the line's points and a tip at the end.

Type: 
VectorObjectBuilder

with_tip_at_the_start(tip_shape) → {VectorObjectBuilder}

Creates a VectorObjectBuilder with the line's points and a tip at the start.

Parameters:
NameTypeDescription
tip_shapeVectorObjectBuilder

The shape of the tip. The shape must be pointing to the right and centered to (0, 0), this function will rotate and move it to the correct angle.

Returns:

A VectorObjectBuilder with the line's points and a tip at the start.

Type: 
VectorObjectBuilder

with_tips_at_both_ends(tip_shape) → {VectorObjectBuilder}

Creates a VectorObjectBuilder with the line's points and tips at both ends.

Parameters:
NameTypeDescription
tip_shapeVectorObjectBuilder

The shape of the tip. The shape must be pointing to the right, this function will rotate and move it to the correct angle.

Returns:

A VectorObjectBuilder with the line's points and tips at both ends.

Type: 
VectorObjectBuilder

y_intercept() → {number}

Returns the y-intercept of the line.

Returns:

The y-intercept of the line.

Type: 
number