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 |
|
Enum where members are also (and must be) strings |
|
Ball transition models must satisfy this protocol |
|
An Enum for different transition models |
|
Returns a transition model |
Classes¶
- class pooltool.physics.resolve.transition.EventType(value)[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.StrEnum
Methods:
- class pooltool.physics.resolve.transition.Ball(id: str, state: BallState = BallState.default, params: BallParams = BallParams.default, ballset: BallSet | None = None, initial_orientation: BallOrientation = BallOrientation.random, history: BallHistory = BallHistory.factory, history_cts: BallHistory = BallHistory.factory)[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
Ball
for a description of the role ofstates
during 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
Ball
for a description of the role ofhistory
during 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.event_based.continuize.continuize()
for a details about continuizing a simulated system.See the Important section in
Ball
for a description of the role ofhistory_cts
during simulation.
Important
To instantiate this class, consider using the
create()
constructor. Or, use functions withinpooltool.layouts
to generate entire collection of balls. Or, of course, construct as normal with__init__
.Important
The following explains how a
Ball
object is modified when its parent system is simulated (pooltool.evolution.event_based.simulate.simulate()
).At the start of the simulation process,
state
represents the ball state at \(t = 0\). A copy ofstate
is appended tohistory
.For each timestep of the simulation,
state
is used to inform how the system should advance forward in time. Once determined,state
is updated to reflect the ball’s new state. A copy ofstate
is appended tohistory
.When the simulation is finished,
state
represents the final resting state of the ball. So too doeshistory[-1]
.Finally, if the system is continuized (see
pooltool.evolution.continuize.continuize()
),history_cts
is 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.sets
for 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
history
andhistory_cts
attributes are both set to emptyBallHistory
objects.- 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
Ball
without directly instancing objects like likepooltool.objects.balls.params.BallParams
andBallState
.- 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.StrEnum(value)[source]¶
Enum where members are also (and must be) strings
- class pooltool.physics.resolve.transition.BallTransitionStrategy(*args, **kwargs)[source]¶
Ball transition models must satisfy this protocol
Bases:
Protocol
Methods:
- 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:
Functions¶
- pooltool.physics.resolve.transition.get_transition_model(model: BallTransitionModel | None = None, params: pooltool.physics.resolve.types.ModelArgs = {}) BallTransitionStrategy [source]¶
Returns a transition model
- Parameters:
model (Optional[BallTransitionModel]) -- An Enum specifying the desired model. If not passed,
CanonicalTransition
is passed with empty params.params (pooltool.physics.resolve.types.ModelArgs) -- A mapping of parameters accepted by the model.
- Returns:
An instantiated model that satisfies the
BallTransitionStrategy
protocol.- Return type:
Attributes¶
- pooltool.physics.resolve.transition.ModelArgs¶
A mapping of argument names to argument values