Class AmoebotFunctions
A collection of constants and utility methods for geometric calculations.
Inheritance
Namespace: AS2
Assembly: .dll
Syntax
public static class AmoebotFunctions
Fields
| Edit this page View SourcehexRadiusMajor
The distance between a hexagon's center and each of its corners
if the triangular grid scale (triangle side length) is 1
.
This is the same as the side length of the hexagon.
Declaration
public static readonly float hexRadiusMajor
Field Value
Type | Description |
---|---|
float |
hexRadiusMajor2
Half of hexRadiusMajor.
Declaration
public static readonly float hexRadiusMajor2
Field Value
Type | Description |
---|---|
float |
hexRadiusMinor
The distance between a hexagon's center and each of its sides if
the triangular grid scale (triangle side length) is 1
.
Declaration
public static readonly float hexRadiusMinor
Field Value
Type | Description |
---|---|
float |
pinPositionCacheHex
Declaration
private static List<Vector2[][]> pinPositionCacheHex
Field Value
Type | Description |
---|---|
List<Vector2[][]> |
pinPositionCacheRound
Declaration
private static List<Vector2[][]> pinPositionCacheRound
Field Value
Type | Description |
---|---|
List<Vector2[][]> |
rotationMatrices
Rotation matrices for counter-clockwise rotations in 60 degree steps.
The matrix at index i rotates by i * 60
degrees.
Declaration
public static readonly Quaternion[] rotationMatrices
Field Value
Type | Description |
---|---|
Quaternion[] |
rotation_0
Declaration
public static readonly Quaternion rotation_0
Field Value
Type | Description |
---|---|
Quaternion |
rotation_120
Declaration
public static readonly Quaternion rotation_120
Field Value
Type | Description |
---|---|
Quaternion |
rotation_180
Declaration
public static readonly Quaternion rotation_180
Field Value
Type | Description |
---|---|
Quaternion |
rotation_240
Declaration
public static readonly Quaternion rotation_240
Field Value
Type | Description |
---|---|
Quaternion |
rotation_300
Declaration
public static readonly Quaternion rotation_300
Field Value
Type | Description |
---|---|
Quaternion |
rotation_60
Declaration
public static readonly Quaternion rotation_60
Field Value
Type | Description |
---|---|
Quaternion |
rowDistVert
The vertical distance between two rows of the triangular grid
if the edge length is 1
. This is equal to the height
of a triangle.
Can be calculated as sin(60)
or sqrt(3)/2
.
Declaration
public static readonly float rowDistVert
Field Value
Type | Description |
---|---|
float |
unitVectors
The six unit grid vectors corresponding to the six cardinal directions
Declaration
public static readonly Vector2Int[] unitVectors
Field Value
Type | Description |
---|---|
Vector2Int[] |
Methods
| Edit this page View SourceAdvancePinPositionCaches(int)
Adds entries to the pin position caches such that the desired number of pins per side is included.
Declaration
private static void AdvancePinPositionCaches(int maxPinsPerSide)
Parameters
Type | Name | Description |
---|---|---|
int | maxPinsPerSide | The desired number of pins
per side. After this, both caches will have length at
least |
AreNodesNeighbors(Vector2Int, Vector2Int)
Checks whether the two given grid nodes are adjacent to each other.
Declaration
public static bool AreNodesNeighbors(Vector2Int node1, Vector2Int node2)
Parameters
Type | Name | Description |
---|---|---|
Vector2Int | node1 | The first grid node. |
Vector2Int | node2 | The second grid node. |
Returns
Type | Description |
---|---|
bool |
|
CalculateRelativePinPosition(PinDef, int, ViewType)
Calculates the relative pin position in world space relative to the particle center based on the abstract pin position definition, the number of pins, the scale and the view type.
Declaration
public static Vector2 CalculateRelativePinPosition(ParticlePinGraphicState.PinDef pinDef, int pinsPerSide, ViewType viewType)
Parameters
Type | Name | Description |
---|---|---|
ParticlePinGraphicState.PinDef | pinDef | The pin whose position to calculate. |
int | pinsPerSide | The number of pins per side. |
ViewType | viewType | The view type used to place the pins. |
Returns
Type | Description |
---|---|
Vector2 | A vector representing the pin's coordinates relative
to the particle's center. Will be |
GetNeighborPosition(Vector2Int, Direction)
Returns the grid coordinates of the given grid node's neighbor in the specified direction.
Declaration
public static Vector2Int GetNeighborPosition(Vector2Int pos, Direction dir)
Parameters
Type | Name | Description |
---|---|---|
Vector2Int | pos | The reference grid position. |
Direction | dir | The direction of the neighbor. Secondary directions are mapped to cardinal directions. |
Returns
Type | Description |
---|---|
Vector2Int | The grid coordinates of the node neighboring
|
GetNeighborPosition(Vector2Int, int)
Returns the grid coordinates of the given grid node's neighbor in the specified direction.
Declaration
public static Vector2Int GetNeighborPosition(Vector2Int pos, int dir)
Parameters
Type | Name | Description |
---|---|---|
Vector2Int | pos | The reference grid position. |
int | dir | The direction of the neighbor,
represented as an int. |
Returns
Type | Description |
---|---|
Vector2Int | The grid coordinates of the node neighboring
|
GetNeighborPositionOffset(int)
Computes the grid unit vector pointing in the indicated direction.
Declaration
public static Vector2Int GetNeighborPositionOffset(int dir)
Parameters
Type | Name | Description |
---|---|---|
int | dir | The direction into which the vector should point,
represented as an int. |
Returns
Type | Description |
---|---|
Vector2Int | A grid unit vector pointing in direction
|
GridToWorldPositionVector2(float, float)
Translates grid coordinates into Cartesian (world) coordinates.
Declaration
public static Vector2 GridToWorldPositionVector2(float gridPosX, float gridPosY)
Parameters
Type | Name | Description |
---|---|---|
float | gridPosX | The grid x coordinate. |
float | gridPosY | The grid y coordinate. |
Returns
Type | Description |
---|---|
Vector2 | The world coordinates corresponding to
|
GridToWorldPositionVector2(Vector2)
Translates grid coordinates into Cartesian (world) coordinates.
Declaration
public static Vector2 GridToWorldPositionVector2(Vector2 gridPos)
Parameters
Type | Name | Description |
---|---|---|
Vector2 | gridPos | The grid coordinates. |
Returns
Type | Description |
---|---|
Vector2 | The world coordinates corresponding to
|
GridToWorldPositionVector3(float, float)
Translates grid coordinates into Cartesian (world) coordinates
with a z component set to 0
.
Declaration
public static Vector3 GridToWorldPositionVector3(float gridPosX, float gridPosY)
Parameters
Type | Name | Description |
---|---|---|
float | gridPosX | The grid x coordinate. |
float | gridPosY | The grid y coordinate. |
Returns
Type | Description |
---|---|
Vector3 | A 3-dimensional vector where the first two components are
the he world coordinates corresponding to |
GridToWorldPositionVector3(float, float, float)
Translates grid coordinates into Cartesian (world) coordinates with a z component.
Declaration
public static Vector3 GridToWorldPositionVector3(float gridPosX, float gridPosY, float z)
Parameters
Type | Name | Description |
---|---|---|
float | gridPosX | The grid x coordinate. |
float | gridPosY | The grid y coordinate. |
float | z |
Returns
Type | Description |
---|---|
Vector3 | A 3-dimensional vector where the first two components are
the he world coordinates corresponding to |
GridToWorldPositionVector3(Vector2)
Translates grid coordinates into Cartesian (world) coordinates
with a z component set to 0
.
Declaration
public static Vector3 GridToWorldPositionVector3(Vector2 gridPos)
Parameters
Type | Name | Description |
---|---|---|
Vector2 | gridPos | The grid coordinates. |
Returns
Type | Description |
---|---|
Vector3 | A 3-dimensional vector where the first two components are
the he world coordinates corresponding to |
GridToWorldPositionVector3(Vector2, float)
Translates grid coordinates into Cartesian (world) coordinates with a z component.
Declaration
public static Vector3 GridToWorldPositionVector3(Vector2 gridPos, float z)
Parameters
Type | Name | Description |
---|---|---|
Vector2 | gridPos | The grid coordinates. |
float | z |
Returns
Type | Description |
---|---|
Vector3 | A 3-dimensional vector where the first two components are
the he world coordinates corresponding to |
HeightDifferenceBetweenRows()
Returns the vertical distance between two rows in the
triangular grid if the edge length is 1
.
Declaration
public static float HeightDifferenceBetweenRows()
Returns
Type | Description |
---|---|
float | The distance between two rows in the triangular grid. |
Remarks
Deprecated. Use rowDistVert instead.
HexVertex_XValue()
The distance between the center of a hexagon and
each of its sides if the triangular grid scale
(triangle side length) is 1
.
Declaration
public static float HexVertex_XValue()
Returns
Type | Description |
---|---|
float | The distance between the center of a hexagon and each of its sides. |
Remarks
Deprecated. Use hexRadiusMinor instead.
HexVertex_YValueSides()
The vertical distance between the center of a hexagon
and the top corners of its vertical sides, if the
triangular grid scale (triangle side length) is 1
.
Declaration
public static float HexVertex_YValueSides()
Returns
Type | Description |
---|---|
float | The vertical distance between the center of a hexagon and the top corners of its vertical sides. |
Remarks
Deprecated. Use hexRadiusMajor2 instead.
HexVertex_YValueTop()
The distance between the center of a hexagon and each
of its corners if the triangular grid scale (triangle
side length) is 1
.
Declaration
public static float HexVertex_YValueTop()
Returns
Type | Description |
---|---|
float | The distance between the center of a hexagon and each of its corners. |
Remarks
Deprecated. Use hexRadiusMajor instead.
RotateVector(Vector2Int, int)
Rotates the given grid position around the origin in counter-clockwise direction.
Declaration
public static Vector2Int RotateVector(Vector2Int vec, int rotation)
Parameters
Type | Name | Description |
---|---|---|
Vector2Int | vec | The grid position to be rotated. |
int | rotation | The number of 60 degree counter-clockwise rotations around the origin. |
Returns
Type | Description |
---|---|
Vector2Int | The rotated vector. |
WorldPositionToNearestNodePosition(Vector2)
Calculates the world coordinates of the grid node closest to the given world coordinates.
Declaration
public static Vector2 WorldPositionToNearestNodePosition(Vector2 worldPosition)
Parameters
Type | Name | Description |
---|---|---|
Vector2 | worldPosition | The world coordinates. |
Returns
Type | Description |
---|---|
Vector2 | The world coordinates of the grid node closest
to |
WorldToGridPosition(Vector2)
Translates Cartesian (world) coordinates into the nearest integer grid coordinates.
Uses the cube coordinate transformation explained in https://www.redblobgames.com/grids/hexagons/#rounding.
Declaration
public static Vector2Int WorldToGridPosition(Vector2 worldPosition)
Parameters
Type | Name | Description |
---|---|---|
Vector2 | worldPosition | The world coordinates. |
Returns
Type | Description |
---|---|
Vector2Int | The grid coordinates corresponding to
|
WorldToGridPositionF(Vector2)
Same as WorldToGridPosition(Vector2) but without rounding the result to the nearest grid cell.
Declaration
public static Vector2 WorldToGridPositionF(Vector2 worldPosition)
Parameters
Type | Name | Description |
---|---|---|
Vector2 | worldPosition | The world coordinates. |
Returns
Type | Description |
---|---|
Vector2 | The grid coordinates corresponding to
|