Skip to content

Commit de36fcc

Browse files
committed
Implement the logic part 2
1 parent 69ea1ea commit de36fcc

File tree

1 file changed

+13
-5
lines changed
  • pooltool/physics/resolve/ball_cushion/unrealistic

1 file changed

+13
-5
lines changed

pooltool/physics/resolve/ball_cushion/unrealistic/__init__.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,15 @@
1313

1414

1515
def _solve(
16-
ball: Ball, cushion: LinearCushionSegment
16+
ball: Ball, cushion: LinearCushionSegment, restitution: bool = True
1717
) -> Tuple[Ball, LinearCushionSegment]:
18-
"""Given ball and cushion, unrealistically reflect the ball's momentum"""
18+
"""Given ball and cushion, unrealistically reflect the ball's momentum
19+
20+
Args:
21+
restitution:
22+
By default, the ball's momentum is reflected without loss. Set this to true
23+
if the ball's restitution coefficient should dampen the outgoing velocity.
24+
"""
1925
rvw = ball.state.rvw
2026

2127
# Two things about the normal:
@@ -40,9 +46,9 @@ def _solve(
4046
rvw_R = ptmath.coordinate_rotation(rvw.T, -psi).T
4147

4248
# Reverse velocity component lying in normal direction
43-
rvw_R[1, 0] *= -1
49+
rvw_R[1, 0] *= -1 * (1 if not restitution else ball.params.e_c)
4450

45-
# Rotate frame of refernce back to the table frame
51+
# Rotate frame of reference back to the table frame
4652
rvw = ptmath.coordinate_rotation(rvw_R.T, psi).T
4753

4854
# Set the ball's rvw
@@ -56,7 +62,9 @@ def _solve(
5662

5763
@attrs.define
5864
class UnrealisticLinear(CoreBallLCushionCollision):
65+
restitution: bool = True
66+
5967
def solve(
6068
self, ball: Ball, cushion: LinearCushionSegment
6169
) -> Tuple[Ball, LinearCushionSegment]:
62-
return _solve(ball, cushion)
70+
return _solve(ball, cushion, self.restitution)

0 commit comments

Comments
 (0)