Path2d

Summary

A set of Vector2 points forming a 2D path

Instance Properties

NameReturn TypeDescription

count

number Read-only

Returns the number of points in this path

this[index]

Transform Read-only

Returns the point at the specified index

last

Transform Read-only

Returns the last point in this path

Class Methods

Path2d:New()

Creates a new empty 2d Path

Returns: Path2d

Example

myPath = Path2d:New()

Path2d:New(positionList)

Creates a 2d path from a list of Vector2 points

Returns: Path2d

Parameters:

NameTypeDefaultDescription

positionList

Vector2[]

The list of points

Example

myPath = Path2d:New({point1, point2, point3})

Path2d:New(positionList)

Creates a path from a list of Vector3 points

Returns: Path2d

Parameters:

NameTypeDefaultDescription

positionList

Vector3[]

The list of points

Example

myPath = Path:New({point1, point2, point3})

Path2d:Polygon(sides)

Generates a regular polygon path

Returns: Path2d (The new path)

Parameters:

NameTypeDefaultDescription

sides

number

The number of sides for the polygon

Example

myPath = Path2d:Polygon(6)

Instance Methods

path2d:Insert(point)

Inserts a new point at the end of the path

Returns: nil

Parameters:

NameTypeDefaultDescription

point

The point to be inserted at the end of the path

Example

myPath:Insert(Transform:New(pos, rot)

path2d:Insert(point, index)

Inserts a new point at the specified index

Returns: nil

Parameters:

NameTypeDefaultDescription

point

The point to be inserted

index

number

The index at which to insert the point

Example

myPath:Insert(transform, index)

path2d:OnX()

Converts the 2D path to a 3D path on the YZ plane (i.e. with all x values set to 0)

Returns: Path (A 3D Path based on the input but with all x as 0: (0, inX, inY))

Example

my3dPath = my2dPath:OnX()

path2d:OnY()

Converts the 2D path to a 3D path on the XZ plane (i.e. with all y values set to 0)

Returns: Path (A 3D Path based on the input but with all y as 0: (inX, 0, inY))

Example

my3dPath = my2dPath:OnY()

path2d:OnZ()

Converts the 2D path to a 3D path on the XY plane (i.e. with all z values set to 0)

Returns: Path (A 3D Path based on the input but with all z as 0: (inX, inY, 0))

Example

my3dPath = my2dPath:OnZ()

path2d:TransformBy(transform)

Transforms all points in the path by the specific amount

Returns: nil

Parameters:

NameTypeDefaultDescription

transform

The transform to be applied to all points in the path

Example

myPath:TransformBy(transform)

path2d:TranslateBy(amount)

Changes the position of all points in the path by a given amount

Returns: nil

Parameters:

NameTypeDefaultDescription

amount

The distance to move the points

Example

myPath:TranslateBy(Vector3:up)

path2d:RotateBy(amount)

Rotates all points in the path around the origin by a given amount

Returns: nil

Parameters:

NameTypeDefaultDescription

amount

The amount by which to rotate the path

Example

myPath:RotateBy(Rotation.New(45, 0, 0)

path2d:ScaleBy(scale)

Scales the path

Returns: nil

Parameters:

NameTypeDefaultDescription

scale

number

The scaling factor to apply to the path

Example

myPath:ScaleBy(2)

path2d:ScaleBy(x, y)

Scales the path

Returns: nil

Parameters:

NameTypeDefaultDescription

x

number

The x scaling factor to apply to the path

y

number

The y scaling factor to apply to the path

Example

myPath:ScaleBy(2, 1)

path2d:ScaleBy(scale)

Scales the path

Returns: nil

Parameters:

NameTypeDefaultDescription

scale

The scaling factor to apply to the path

Example

myPath:ScaleBy(myVector2

path2d:Center()

Moves all points on the path so that their common center is the origin

Returns: nil

Example

myPath:Center()

path2d:StartingFrom(index)

Reorders the points so that point at the given index is shifted to be the first point

Returns: nil

Parameters:

NameTypeDefaultDescription

index

number

The index of the point to make the new first point

Example

myPath:StartingFrom(3)

path2d:FindClosest(point)

Returns the index of the point closest to the given position

Returns: number

Parameters:

NameTypeDefaultDescription

point

The 3D position that we are seeking the closest to

Example

myPath:FindClosest(Vector3:New(10, 2, 4)

path2d:FindMinimumX()

Returns the index of the point with the smallest X value

Returns: number

Example

myPath:FindMinimumX()

path2d:FindMinimumY()

Returns the index of the point with the smallest Y value

Returns: number

Example

myPath:FindMinimumY()

path2d:FindMaximumX()

Returns the index of the point with the biggest X value

Returns: number

Example

myPath:FindMaximumX()

path2d:FindMaximumY()

Returns the index of the point with the biggest Y value

Returns: number

Example

myPath:FindMaximumY()

path2d:Normalize(size)

Scales and shifts all points so that they fit in a 1 unit square at the origin

Returns: nil

Parameters:

NameTypeDefaultDescription

size

number

1

The size of the square to fit the path into

Example

myPath:Normalize(size)

path2d:Resample(spacing)

Resamples the path at a specified spacing

Returns: nil (The resampled path)

Parameters:

NameTypeDefaultDescription

spacing

number

The space between points in the new pat

Example

myPath:Resample(spacing)

Last updated