Skip to content

Position

gradysim.protocol.position

This module contains some helpers useful when working with positions. Positions are used to localize the nodes inside the python simulation.

Position = Tuple[float, float, float] module-attribute

Represents a node's position inside the simulation. It is a tuple of three floating point numbers representing the euclidean coordinates of the node.

squared_distance(start, end)

Calculates the squared distance between two positions.

Parameters:

Name Type Description Default
start Position

First position

required
end Position

Second position

required

Returns:

Type Description
float

The distance squared

Source code in gradysim/protocol/position.py
def squared_distance(start: Position, end: Position) -> float:
    """
    Calculates the squared distance between two positions.

    Args:
        start: First position
        end: Second position

    Returns:
        The distance squared
    """
    return (end[0] - start[0]) ** 2 + (end[1] - start[1]) ** 2 + (end[2] - start[2]) ** 2