Search Results for

    Show / Hide Table of Contents

    Class AmoebotFunctions

    A collection of constants and utility methods for geometric calculations.

    Inheritance
    object
    AmoebotFunctions
    Namespace: AS2
    Assembly: .dll
    Syntax
    public static class AmoebotFunctions

    Fields

    | Edit this page View Source

    hexRadiusMajor

    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
    | Edit this page View Source

    hexRadiusMajor2

    Half of hexRadiusMajor.

    Declaration
    public static readonly float hexRadiusMajor2
    Field Value
    Type Description
    float
    | Edit this page View Source

    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
    | Edit this page View Source

    pinPositionCacheHex

    Declaration
    private static List<Vector2[][]> pinPositionCacheHex
    Field Value
    Type Description
    List<Vector2[][]>
    | Edit this page View Source

    pinPositionCacheRound

    Declaration
    private static List<Vector2[][]> pinPositionCacheRound
    Field Value
    Type Description
    List<Vector2[][]>
    | Edit this page View Source

    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[]
    | Edit this page View Source

    rotation_0

    Declaration
    public static readonly Quaternion rotation_0
    Field Value
    Type Description
    Quaternion
    | Edit this page View Source

    rotation_120

    Declaration
    public static readonly Quaternion rotation_120
    Field Value
    Type Description
    Quaternion
    | Edit this page View Source

    rotation_180

    Declaration
    public static readonly Quaternion rotation_180
    Field Value
    Type Description
    Quaternion
    | Edit this page View Source

    rotation_240

    Declaration
    public static readonly Quaternion rotation_240
    Field Value
    Type Description
    Quaternion
    | Edit this page View Source

    rotation_300

    Declaration
    public static readonly Quaternion rotation_300
    Field Value
    Type Description
    Quaternion
    | Edit this page View Source

    rotation_60

    Declaration
    public static readonly Quaternion rotation_60
    Field Value
    Type Description
    Quaternion
    | Edit this page View Source

    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
    | Edit this page View Source

    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 Source

    AdvancePinPositionCaches(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 maxPinsPerSide.

    | Edit this page View Source

    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

    true if and only if node1 and node2 are adjacent to each other.

    | Edit this page View Source

    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 (0, 0) if the viewType is not Hexagonal or HexagonalCirc.

    | Edit this page View Source

    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 pos in direction dir.

    | Edit this page View Source

    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. 0 means East and direction values increase in counter-clockwise direction.

    Returns
    Type Description
    Vector2Int

    The grid coordinates of the node neighboring pos in direction dir.

    | Edit this page View Source

    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. 0 means East and direction values increase in counter-clockwise direction.

    Returns
    Type Description
    Vector2Int

    A grid unit vector pointing in direction dir.

    | Edit this page View Source

    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 gridPosX and gridPosY.

    | Edit this page View Source

    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 gridPos.

    | Edit this page View Source

    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 gridPosX and gridPosY, and the third component is 0.

    | Edit this page View Source

    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 gridPosX and gridPosY, and the third component has the value z.

    | Edit this page View Source

    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 gridPos and the third component is 0.

    | Edit this page View Source

    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 gridPos and the third component has the value z.

    | Edit this page View Source

    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.

    | Edit this page View Source

    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.

    | Edit this page View Source

    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.

    | Edit this page View Source

    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.

    | Edit this page View Source

    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.

    | Edit this page View Source

    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 worldPosition.

    | Edit this page View Source

    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 worldPosition, rounded to the nearest grid cell.

    | Edit this page View Source

    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 worldPosition.

    • Edit this page
    • View Source
    In this article
    Back to top AmoebotSim 2.0 Documentation v1.11
    Copyright © 2025 AmoebotSim 2.0 Authors
    Generated by DocFX