pooltool.objects.table.components#
Houses all components that make up a table (pockets, cushions, etc)#
Overview#
An Enum for the direction of a cushion |
|
A linear cushion segment defined by the line between points p1 and p2 |
|
A circular cushion segment defined by a circle center and radius |
|
A collection of cushion segments |
|
A circular pocket |
Classes#
- class pooltool.objects.table.components.CushionDirection[source]#
An Enum for the direction of a cushion
Important for constructing cushions if simulation performance speed is required.
For most table geometries, the playing surface only exists on one side of the cushion, so collisions only need to be checked for one direction. This direction can be specified with this class’s attributes.
- SIDE1#
Use side 1.
- SIDE2#
Use side 2.
- BOTH#
Use sides 1 and 2.
Unfortunately, the rule governing whether to use
SIDE1orSIDE2is not clear and instead requires experimentation.If
BOTHis used, both collision checks are performed which makes collision checks twice as slow.Note
This used to inherit from
Enum, but accessing the cushion direction inget_next_ball_linear_cushion_collisionsomehow took up 20% of the functions runtime so I removed it.
- class pooltool.objects.table.components.LinearCushionSegment(id: str, p1: ndarray[Any, dtype[float64]], p2: ndarray[Any, dtype[float64]], direction: int = 2)[source]#
A linear cushion segment defined by the line between points p1 and p2
- p1#
The 3D coordinate where the cushion segment starts.
Note
p1 and p2 must share the same height (
p1[2] == p2[2]).
- Type:
numpy.ndarray[Any, numpy.dtype[numpy.float64]]
- p2#
The 3D coordinate where the cushion segment ends.
Note
p1 and p2 must share the same height (
p1[2] == p2[2]).
- Type:
numpy.ndarray[Any, numpy.dtype[numpy.float64]]
- direction#
The cushion direction (default =
CushionDirection.BOTH).See
CushionDirectionfor explanation.- Type:
Methods:
- height() float#
The height of the cushion
Cached Property Note
This is a cached property, and should be accessed as an attribute, not as a method call.
- Return type:
- lx() float#
The x-coefficient (\(l_x\)) of the cushion’s 2D general form line equation
Cached Property Note
This is a cached property, and should be accessed as an attribute, not as a method call.
The cushion’s general form line equation in the \(XY\) plane (i.e. dismissing the z-component) is
\[l_x x + l_y y + l_0 = 0\]where
\[\begin{split}\begin{align*} l_x &= -\frac{p_{2y} - p_{1y}}{p_{2x} - p_{1x}} \\ l_y &= 1 \\ l_0 &= \frac{p_{2y} - p_{1y}}{p_{2x} - p_{1x}} p_{1x} - p_{1y} \\ \end{align*}\end{split}\]- Return type:
- ly() float#
The x-coefficient (\(l_y\)) of the cushion’s 2D general form line equation
See
lx()for definition.Cached Property Note
This is a cached property, and should be accessed as an attribute, not as a method call.
- Return type:
- l0() float#
The constant term (\(l_0\)) of the cushion’s 2D general form line equation
See
lx()for definition.Cached Property Note
This is a cached property, and should be accessed as an attribute, not as a method call.
- Return type:
- normal() numpy.typing.NDArray[numpy.float64]#
The line’s normal vector, with the z-component set to 0.
Warning
The returned normal vector is arbitrarily directed, meaning it may point away from the table surface, rather than towards it. This nonideality is properly handled in downstream simulation logic, however if you’re using this method for custom purposes, you may want to reverse the direction of this vector by negating it.
- Return type:
numpy.typing.NDArray[numpy.float64]
- get_normal(rvw: numpy.typing.NDArray[numpy.float64]) numpy.typing.NDArray[numpy.float64][source]#
Calculates the normal vector
Warning
The returned normal vector is arbitrarily directed, meaning it may point away from the table surface, rather than towards it. This nonideality is properly handled in downstream simulation logic, however if you’re using this method for custom purposes, you may want to reverse the direction of this vector by negating it.
- Parameters:
rvw (numpy.typing.NDArray[numpy.float64]) --
The kinematic state vectors of the contacting balls.
See
rvwparameter ofpooltool.objects.ball.datatypes.BallState.- Returns:
The line’s normal vector, with the z-component set to 0.
- Return type:
NDArray[np.float64]
Note
This method only exists for call signature parity with
CircularCushionSegment.get_normal(). Consider usingnormal()instead.
- copy() LinearCushionSegment[source]#
Create a copy
- Return type:
- class pooltool.objects.table.components.CircularCushionSegment(id: str, center: ndarray[Any, dtype[float64]], radius: float)[source]#
A circular cushion segment defined by a circle center and radius
- center#
A length-3 array specifying the circular cushion’s center.
center[0],center[1], andcenter[2]are the x-, y-, and z-coordinates of the cushion’s center. The circle is assumed to be parallel to the XY plane, which makescenter[2]is the height of the cushion.- Type:
numpy.ndarray[Any, numpy.dtype[numpy.float64]]
Methods:
- height() float#
The height of the cushion
Cached Property Note
This is a cached property, and should be accessed as an attribute, not as a method call.
- Return type:
- a() float#
The x-coordinate of the cushion’s center
Cached Property Note
This is a cached property, and should be accessed as an attribute, not as a method call.
- Return type:
- b() float#
The y-coordinate of the cushion’s center
Cached Property Note
This is a cached property, and should be accessed as an attribute, not as a method call.
- Return type:
- get_normal(rvw: numpy.typing.NDArray[numpy.float64]) numpy.typing.NDArray[numpy.float64][source]#
Calculates the normal vector for a ball contacting the cushion
Assumes that the ball is in fact in contact with the cushion.
- Parameters:
rvw (numpy.typing.NDArray[numpy.float64]) -- The kinematic state vectors of the contacting ball (see
- Return type:
numpy.typing.NDArray[numpy.float64]
:param
pooltool.objects.ball.datatypes.BallState.rvw).:- Returns:
The normal vector, with the z-component set to 0.
- Return type:
NDArray[np.float64]
- copy() CircularCushionSegment[source]#
Create a copy
- Return type:
- class pooltool.objects.table.components.CushionSegments(linear: Dict[str, LinearCushionSegment], circular: Dict[str, CircularCushionSegment])[source]#
A collection of cushion segments
Cushion segments can be either linear (see
LinearCushionSegment) or circular (seeCircularCushionSegment). This class stores both.- linear#
A dictionary of linear cushion segments.
Warning
Keys must match the value IDs, e.g.
{"2": LinearCushionSegment(id="2", ...)}
- circular#
A dictionary of circular cushion segments.
Warning
Keys must match the value IDs, e.g.
{"2t": CircularCushionSegment(id="2t", ...)}
Methods:
- copy() CushionSegments[source]#
Create a copy
- Return type:
- class pooltool.objects.table.components.Pocket(id: str, center: ndarray[Any, dtype[float64]], radius: float, depth: float = 0.08, contains: set = UNKNOWN)[source]#
A circular pocket
- center#
A length-3 array specifying the pocket’s position.
center[0]is the x-coordinate of the pocket’s centercenter[1]is the y-coordinate of the pocket’s centercenter[2]must be 0.0
- Type:
numpy.ndarray[Any, numpy.dtype[numpy.float64]]
Methods:
- a() float#
The x-coordinate of the pocket’s center
Cached Property Note
This is a cached property, and should be accessed as an attribute, not as a method call.
- Return type:
- b() float#
The y-coordinate of the pocket’s center
Cached Property Note
This is a cached property, and should be accessed as an attribute, not as a method call.
- Return type: