Path2d
Summary
A set of Vector2 points forming a 2D path
Instance Properties
Name | Return Type | Description |
---|---|---|
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
Path2d:New(positionList)
Creates a 2d path from a list of Vector2 points
Returns: Path2d
Parameters:
Name | Type | Default | Description |
---|---|---|---|
positionList | Vector2[] | The list of points |
Example
Path2d:New(positionList)
Creates a path from a list of Vector3 points
Returns: Path2d
Parameters:
Name | Type | Default | Description |
---|---|---|---|
positionList | Vector3[] | The list of points |
Example
Path2d:Polygon(sides)
Generates a regular polygon path
Returns: Path2d (The new path)
Parameters:
Name | Type | Default | Description |
---|---|---|---|
sides | number | The number of sides for the polygon |
Example
Instance Methods
path2d:Insert(point)
Inserts a new point at the end of the path
Returns: nil
Parameters:
Name | Type | Default | Description |
---|---|---|---|
point | The point to be inserted at the end of the path |
Example
path2d:Insert(point, index)
Inserts a new point at the specified index
Returns: nil
Parameters:
Name | Type | Default | Description |
---|---|---|---|
point | The point to be inserted | ||
index | number | The index at which to insert the point |
Example
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
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
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
path2d:TransformBy(transform)
Transforms all points in the path by the specific amount
Returns: nil
Parameters:
Name | Type | Default | Description |
---|---|---|---|
transform | The transform to be applied to all points in the path |
Example
path2d:TranslateBy(amount)
Changes the position of all points in the path by a given amount
Returns: nil
Parameters:
Name | Type | Default | Description |
---|---|---|---|
amount | The distance to move the points |
Example
path2d:RotateBy(amount)
Rotates all points in the path around the origin by a given amount
Returns: nil
Parameters:
Name | Type | Default | Description |
---|---|---|---|
amount | The amount by which to rotate the path |
Example
path2d:ScaleBy(scale)
Scales the path
Returns: nil
Parameters:
Name | Type | Default | Description |
---|---|---|---|
scale | number | The scaling factor to apply to the path |
Example
path2d:ScaleBy(x, y)
Scales the path
Returns: nil
Parameters:
Name | Type | Default | Description |
---|---|---|---|
x | number | The x scaling factor to apply to the path | |
y | number | The y scaling factor to apply to the path |
Example
path2d:ScaleBy(scale)
Scales the path
Returns: nil
Parameters:
Name | Type | Default | Description |
---|---|---|---|
scale | The scaling factor to apply to the path |
Example
path2d:Center()
Moves all points on the path so that their common center is the origin
Returns: nil
Example
path2d:StartingFrom(index)
Reorders the points so that point at the given index is shifted to be the first point
Returns: nil
Parameters:
Name | Type | Default | Description |
---|---|---|---|
index | number | The index of the point to make the new first point |
Example
path2d:FindClosest(point)
Returns the index of the point closest to the given position
Returns: number
Parameters:
Name | Type | Default | Description |
---|---|---|---|
point | The 3D position that we are seeking the closest to |
Example
path2d:FindMinimumX()
Returns the index of the point with the smallest X value
Returns: number
Example
path2d:FindMinimumY()
Returns the index of the point with the smallest Y value
Returns: number
Example
path2d:FindMaximumX()
Returns the index of the point with the biggest X value
Returns: number
Example
path2d:FindMaximumY()
Returns the index of the point with the biggest Y value
Returns: number
Example
path2d:Normalize(size)
Scales and shifts all points so that they fit in a 1 unit square at the origin
Returns: nil
Parameters:
Name | Type | Default | Description |
---|---|---|---|
size | number | 1 | The size of the square to fit the path into |
Example
path2d:Resample(spacing)
Resamples the path at a specified spacing
Returns: nil (The resampled path)
Parameters:
Name | Type | Default | Description |
---|---|---|---|
spacing | number | The space between points in the new pat |
Example
Last updated