Common#
Collects some basic classes used in other modules as well as useful methods.
- class common.Angle(rad: float)#
Bases:
float
A simple angle class for representing an angle as both radians and degrees.
- deg() float #
Get the angle in degrees :return: Degrees :rtype: float
- norm() Angle #
Gets the normalized angle within the range of [0°, 360°] :return: The normalized angle :rtype: Angle
- rad() float #
Get the angle in radians :return: :rtype:
- class common.Vector(x: int | float, y: int | float)#
Bases:
object
Represents a simple 2-dimensional vector
- cross(other) float #
Obtains the cross product of t.
- Parameters:
other (Vector) – The second vector
- Returns:
The cross product
- Return type:
float
- distance(other: Vector) float #
Obtains the euclidean distance between the two given vertices.
- Parameters:
other (Vector) – The second vector
- Returns:
The euclidean distance
- Return type:
float
- dot(other) float #
Obtains the dot product of the two given vertices.
- Parameters:
other (Vector) – The second vector
- Returns:
The dot product
- Return type:
float
- static from_point(pos: Tuple[int | float, int | float]) Vector #
Converts a tuple into a vector.
- Parameters:
pos – position tuple
- Returns:
the converted vector
- Return type:
- len() float #
Obtains the length of the vector.
- Returns:
Length of the vector
- Return type:
float
- rad() Angle #
Obtains the radian of the vector as an angle object.
- Returns:
An angle between 0° and 360°
- Return type:
- common.barycenter(points: List) Vector #
Calculates the barycenter of the given point set, i.e. the average point. :param points: List of tuples representing the points :type points: List :return: The barycenter :rtype: List
- common.circle_from_three_points(a: Vector, b: Vector, c: Vector) Tuple[Vector, float] #
Calculates the unique circle \(C\) defined by a, b and c with all points on the perimeter of \(C\).
- Parameters:
a (gdMetriX.Vector) – Point a
b (gdMetriX.Vector) – Point b
c (gdMetriX.Vector) – Point c
- Returns:
The circle \(C\)
- Return type:
gdMetriX.Circle
- common.circle_from_two_points(a: Vector, b: Vector) Tuple[Vector, float] #
Calculates the smallest circle \(C\) with a and b on the perimeter of \(C\).
- Parameters:
a (gdMetriX.Vector) – Point a
b (gdMetriX.Vector) – Point b
- Returns:
The circle \(C\)
- Return type:
gdMetriX.Circle
- common.euclidean_distance(point_a: Tuple[int | float, int | float], point_b: Tuple[int | float, int | float]) float #
Obtains the euclidean distance between point_a and point_b.
- Parameters:
point_a (Tuple[numeric]) – Point a
point_b (Tuple[numeric]) – Point b
- Returns:
Euclidean distance
- Return type:
float
- common.get_node_positions(g, pos: str | dict | None = None) dict #
Tries to obtain the node positions for the given graph.
- If
pos is not supplied: Returns the positions of the ‘pos’ property in the graph - if present
pos is given as a string: Returns the positions saved in the properties of the graph under the that name
pos is a dictionary: Simply returns the given dictionary
- Parameters:
g (nx.Graph) – A networkX graph
pos (Union[str, dict, None]) – Optional position value
- Returns:
The node positions of the given graph
- Return type:
dict