pooltool.physics.resolve.ball_cushion.unrealistic¶
An unrealistic ball-cushion model¶
Overview¶
A billiards ball |
|
A circular cushion segment defined by a circle center and radius |
|
A linear cushion segment defined by the line between points p1 and p2 |
|
Operations used by every ball-linear cushion collision resolver |
|
Operations used by every ball-linear cushion collision resolver |
|
An Enum for different ball-circular cushion collision models |
|
An Enum for different ball-linear cushion collision models |
|
Operations used by every ball-linear cushion collision resolver |
|
Operations used by every ball-linear cushion collision resolver |
Classes¶
- class pooltool.physics.resolve.ball_cushion.unrealistic.Ball(id: str, state: BallState = NOTHING, params: BallParams = NOTHING, ballset: BallSet | None = None, initial_orientation: BallOrientation = NOTHING, history: BallHistory = NOTHING, history_cts: BallHistory = NOTHING)[source]¶
A billiards ball
This class represents a billiards ball. It stores its parameters (mass, radius, etc.), it’s state (coordinates, velocity, spin, etc), its history (a time-resolved trajectory of its state), amongst other things.
- state¶
The ball’s state.
This is the current state of the ball.
See also
See the Important section in
Ballfor a description of the role ofstatesduring simulation.
- params¶
The ball’s physical parameters.
The physical parameters of the ball.
- ballset¶
The ball set that the ball belongs to.
Important if rendering the ball in a scene.
See also
See
Ball.set_ballset()for details
- Type:
- initial_orientation¶
The initial rendered orientation of the ball.
Important if rendering the ball in a scene.
This is the orientation of the ball at \(t = 0\).
- history¶
The ball’s state history
The historical states of the ball from \(t_{initial}\) to \(t_{final}\).
See also
See the Important section in
Ballfor a description of the role ofhistoryduring simulation.
- history_cts¶
The ball’s continuous state history
The historical states of the ball from \(t_{initial}\) to \(t_{final}\) densely sampled with respect to time.
See also
See
pooltool.evolution.continuize.continuize()for a details about continuizing a simulated system.See the Important section in
Ballfor a description of the role ofhistory_ctsduring simulation.
Important
To instantiate this class, consider using the
create()constructor. Or, use functions withinpooltool.layoutsto generate entire collection of balls. Or, of course, construct as normal with__init__.Important
The following explains how a
Ballobject is modified when its parent system is simulated (pooltool.evolution.event_based.simulate.simulate()).At the start of the simulation process,
staterepresents the ball state at \(t = 0\). A copy ofstateis appended tohistory.For each timestep of the simulation,
stateis used to inform how the system should advance forward in time. Once determined,stateis updated to reflect the ball’s new state. A copy ofstateis appended tohistory.When the simulation is finished,
staterepresents the final resting state of the ball. So too doeshistory[-1].Finally, if the system is continuized (see
pooltool.evolution.continuize.continuize()),history_ctsis populated. Otherwise it remains empty.- property xyz¶
The displacement (from origin) vector of the ball.
A shortcut for
self.state.rvw[0].
- property vel¶
The velocity vector of the ball.
A shortcut for
self.state.rvw[1].
- property avel¶
The angular velocity vector of the ball.
A shortcut for
self.state.rvw[2].
Methods:
- set_ballset(ballset: pooltool.objects.ball.sets.BallSet) None[source]¶
Update the ballset
- Raises:
ValueError -- If the ball ID doesn’t match to a model name of the ballset.
See also
See
pooltool.objects.ball.setsfor details about ball sets.See
pooltool.system.datatypes.System.set_ballset()for setting the ballset for all the balls in a system.
- copy(drop_history: bool = False) Ball[source]¶
Create a copy
- Parameters:
drop_history (bool) -- If True, the returned copy
historyandhistory_ctsattributes are both set to emptyBallHistoryobjects.- Return type:
- static create(id: str, *, xy: Sequence[float] | None = None, ballset: pooltool.objects.ball.sets.BallSet | None = None, **kwargs) Ball[source]¶
Create a ball using keyword arguments.
This constructor flattens the tunable parameter space, allowing one to construct a
Ballwithout directly instancing objects like likepooltool.objects.balls.params.BallParamsandBallState.- Parameters:
xy (Optional[Sequence[float]]) -- The x and y coordinates of the ball position.
ballset (Optional[pooltool.objects.ball.sets.BallSet]) -- A ballset.
**kwargs -- Arguments accepted by
pooltool.objects.balls.params.BallParams
- Return type:
- class pooltool.physics.resolve.ball_cushion.unrealistic.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]]
- property 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:
- property 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:
- property 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:
Methods:
- 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.physics.resolve.ball_cushion.unrealistic.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:
- property 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:
- property 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:
- property 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:
- property 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:
- property 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]
Methods:
- 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.physics.resolve.ball_cushion.unrealistic.CoreBallCCushionCollision[source]¶
Operations used by every ball-linear cushion collision resolver
Bases:
abc.ABCMethods:
- make_kiss(ball: pooltool.objects.ball.datatypes.Ball, cushion: pooltool.objects.table.components.CircularCushionSegment) pooltool.objects.ball.datatypes.Ball[source]¶
Translate the ball so it (almost) touches the circular cushion segment
This makes a correction such that if the ball is not a distance R from the cushion, the ball is moved along the normal such that it is. To avoid downstream float precision round-off error, a small epsilon of additional distance (constants.EPS_SPACE) is put between them, ensuring the cushion and ball are separated post-resolution.
- Return type:
- class pooltool.physics.resolve.ball_cushion.unrealistic.CoreBallLCushionCollision[source]¶
Operations used by every ball-linear cushion collision resolver
Bases:
abc.ABCMethods:
- make_kiss(ball: pooltool.objects.ball.datatypes.Ball, cushion: pooltool.objects.table.components.LinearCushionSegment) pooltool.objects.ball.datatypes.Ball[source]¶
Translate the ball so it (almost) touches the linear cushion segment
This makes a correction such that if the ball is not a distance R from the cushion, the ball is moved along the normal such that it is. To avoid downstream float precision round-off error, a small epsilon of additional distance (constants.EPS_SPACE) is put between them, ensuring the cushion and ball are separated post-resolution.
- Return type:
- class pooltool.physics.resolve.ball_cushion.unrealistic.BallCCushionModel(value, names=<not given>, *values, module=None, qualname=None, type=None, start=1, boundary=None)[source]¶
An Enum for different ball-circular cushion collision models
- UNREALISTIC¶
An unrealistic model in which balls are perfectly reflected. Spin is left untouched by the interaction.
Bases:
pooltool.utils.strenum.StrEnum
- class pooltool.physics.resolve.ball_cushion.unrealistic.BallLCushionModel(value, names=<not given>, *values, module=None, qualname=None, type=None, start=1, boundary=None)[source]¶
An Enum for different ball-linear cushion collision models
- UNREALISTIC¶
An unrealistic model in which balls are perfectly reflected. Spin is left untouched by the interaction.
Bases:
pooltool.utils.strenum.StrEnum
- class pooltool.physics.resolve.ball_cushion.unrealistic.UnrealisticLinear(restitution: bool = False)[source]¶
Bases:
pooltool.physics.resolve.ball_cushion.core.CoreBallLCushionCollision
- class pooltool.physics.resolve.ball_cushion.unrealistic.UnrealisticCircular(restitution: bool = False)[source]¶
Bases:
pooltool.physics.resolve.ball_cushion.core.CoreBallCCushionCollision