pooltool.physics.resolve.transition¶
Defining and handling ball state transitions¶
Note
If this module is ever extended to support multiple treatments for ball transitions, expand this file into a file structure modelled after ../ball_ball or ../ball_cushion
Overview¶
An Enum of event types |
|
A billiards ball |
|
An Enum for different transition models |
|
Ball transition models must satisfy this protocol |
Classes¶
- class pooltool.physics.resolve.transition.EventType(value, names=<not given>, *values, module=None, qualname=None, type=None, start=1, boundary=None)[source]¶
An Enum of event types
- NONE¶
The null event.
- BALL_BALL¶
A ball-ball collision.
- BALL_LINEAR_CUSHION¶
A ball collision with a linear cushion segment.
- BALL_CIRCULAR_CUSHION¶
A ball collision with a circular cushion segment.
- BALL_POCKET¶
A ball pocket “collision”. This marks the point at which the ball crosses the point of no return.
- STICK_BALL¶
A cue-stick ball collision.
- SPINNING_STATIONARY¶
A ball transition from spinning to stationary.
- ROLLING_STATIONARY¶
A ball transition from rolling to stationary.
- ROLLING_SPINNING¶
A ball transition from rolling to spinning.
- SLIDING_ROLLING¶
A ball transition from sliding to rolling.
Bases:
pooltool.utils.strenum.StrEnumMethods:
- class pooltool.physics.resolve.transition.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.transition.BallTransitionModel(value, names=<not given>, *values, module=None, qualname=None, type=None, start=1, boundary=None)[source]¶
An Enum for different transition models
- CANONICAL¶
Sets the ball to appropriate state. Sets any residual quantities to 0 when appropriate.
Bases:
pooltool.utils.strenum.StrEnum
- class pooltool.physics.resolve.transition.BallTransitionStrategy(*args, **kwargs)[source]¶
Ball transition models must satisfy this protocol
Bases:
ProtocolMethods:
- resolve(ball: pooltool.objects.ball.datatypes.Ball, transition: pooltool.events.datatypes.EventType, inplace: bool = False) pooltool.objects.ball.datatypes.Ball[source]¶
This method resolves a ball transition
- Return type: