Giter Site home page Giter Site logo

Comments (8)

ekiefl avatar ekiefl commented on July 26, 2024

Hey tailuge,

Thanks for reaching out.

phi = math.angle(rvw_R[1]) % (2 * np.pi) is always a +ve quantity

Well I noticed that math.angle(...) itself always returns a positive value:

>>> import numpy as np
>>> import pooltool.math as math
>>> any([math.angle(np.random.randint(-10,10, size=3)) < 0 for _ in range(10000)])
False

So in my case, the modulo is not collapsing directionality in the y-direction. Probably because math.angle is different than arctan2:

@jit(nopython=True, cache=const.numba_cache)
def angle(v2, v1=(1, 0)):
    """Returns counter-clockwise angle of projections of v1 and v2 onto the x-y plane

    (just-in-time compiled)
    """
    ang = np.arctan2(v2[1], v2[0]) - np.arctan2(v1[1], v1[0])

    if ang < 0:
        return 2 * np.pi + ang

    return ang

As for the difference between my code and yours, I'm not sure. I could be accounting for direction in some other way during my coordinate rotation?

I set up a test case bouncing a ball to two symmetrically equivalent directions and observed that the outcomes were not matching

I assume you discovered this in your project, not pooltool, right?

In general, testing for symmetrical equations is a good idea. I am on vacation but you've prompted me to start thinking about adding such a test. It could cover the Han model and all future models. Maybe I could make a test_ball_cushion.py in pooltool/physics/resolve/ball_cushion/ and maybe it would look something like this:

import pytest
import attrs
from pooltool.system.datatypes import System
from pooltool.physics.resolve.ball_cushion import BallLCushionModel, get_ball_lin_cushion_model
from pooltool.physics.resolve.resolver import Resolver

@pytest.mark.parametrize("model_name", [BallLCushionModel.HAN_2005])
def test_symmetry(model_name) -> None:
    shot = System.example
    
    model = get_ball_lin_cushion_model(model_name)
    resolver = attrs.evolve(Resolver.default, ball_linear_cushion=model)

    # Simulate the shot and the reflected shot, assert isomorphic trajectories

I guess I will keep this issue open until I add symmetric physics tests, but as of yet I don't think this is a pooltool bug.

from pooltool.

tailuge avatar tailuge commented on July 26, 2024

You make a good point that in your code Math.angle is always positive so the modulo makes no difference. I only noticed the problem in my implementation but I think the principle is the same that we rotate the ball to always bounce in +X cushion.

Adding a test is a good idea, the problem is apparent when the ball bounces at a shallow angle with 'slip' i.e. when Pzs > Pze.

My test case that broke without the correction is this one:

https://github.com/tailuge/billiards/blob/ade19d03c726bc414c3c4971fe1241dd029decc1/test/model/cushion.spec.ts#L192

from pooltool.

ekiefl avatar ekiefl commented on July 26, 2024

Ok I hear you. Nice test set by the way, maybe I should use it as a template for my own test set.

In the example you link, you set vx and vy. Does the ball have any spin or is that, along with the parameters you set, all that's required for the slipping case?

from pooltool.

tailuge avatar tailuge commented on July 26, 2024

In that test there is no spin i.e. rvel=(0,0,0) this results in a slipping cushion bounce.

from pooltool.

ekiefl avatar ekiefl commented on July 26, 2024

Ok great, thanks.

I'm really interested to hear about your project by the way. So nice you can play it on the browser!

from pooltool.

tailuge avatar tailuge commented on July 26, 2024

I have worked on and off on my implementation for years, but only this year I read your blog and the corrections you pointed out on the Han paper (I've referenced you in the readme). Thank you for posting that, I feel like it gave me a big breakthrough in the physics model.

from pooltool.

tailuge avatar tailuge commented on July 26, 2024

The only benefit of running in a browser is you can send someone a link to your break

from pooltool.

ekiefl avatar ekiefl commented on July 26, 2024

Thank you for posting that, I feel like it gave me a big breakthrough in the physics model.

You're very welcome, I'm glad you found it.

I added symmetric tests for a variety of incoming angles. This includes cases where the Han model slips. The test lives in test_ball_cushion.py and can be applied to all existing ball-cushion models.

By the way, if you want to collaborate or bounce ideas off one another, you should join the developer discord: https://discord.gg/jAbQRWR3

from pooltool.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.