- #1
gogreengo
- 12
- 0
Hi all,
First off, I apologise if this is the incorrect section for this post and for my lack of maths skills and my ignorance.
I've have been struggling with this issue for a few weeks now without success so I'm turning to you experts for any assistance/guidance you can provide.
I am creating a pool (8 ball/billiards) simulation mostly based on the theory presented in this paper: An event-based pool physics simulator
And as a starting base, I'm extending this implementation: http://www.stanford.edu/group/billiards/FastFiz/main.html
This is working really well except neither the paper nor the FastFiz implementation support or model the jaws of the pockets. Instead a ball is considered 'pocketed' when it enters the opening of the pocket boundary.
I am attempting to include the jaws as shown here:
(I need all the jaws, the image is just to show what I mean by 'jaws')
The event simulation uses gsl_poly_solve_quadratic from the GNU Scientific Library to calculate the time a collision with a rail or pocket will occur given the current state of a ball.
Due to my poor maths skills I can only express the situation in code rather than equations, I hope that is acceptable here.
For example the resulting code for a south rail collision is:
Where mu is the coefficient of friction, Table::g is gravity, u_hat is the velocity vector normal (when rolling) or "(v + (Vector(0, 0, 1).cross(ball.getSpin()) * ball.getRadius())).norm()" when sliding. v is the velocity vector and r is the current ball position.
And for the south west pocket would be:
Now it's trivial to move the pocket backwards deeper into the real pocket by removing the "- cp_width" from the quadratic, this works just fine, but I'm having enormous difficulty doing the same for the jaws in the pocket. I can get it to function but the collision events are not occurring anywhere near where the jaws should be.
For example, I've added two jaws to the south west pocket like so:
But this just doesn't work, the jaw rail collisions occur well behind the pockets and on the wrong angle.
Does anyone have any idea where I'm going wrong? Does what I'm doing even make sense?
I hope I haven't missed any relevant information here.
Again I apologise for my ignorance here.
Any assistance or guidance will be greatly appreciated.
Regards,
Lark.
First off, I apologise if this is the incorrect section for this post and for my lack of maths skills and my ignorance.
I've have been struggling with this issue for a few weeks now without success so I'm turning to you experts for any assistance/guidance you can provide.
I am creating a pool (8 ball/billiards) simulation mostly based on the theory presented in this paper: An event-based pool physics simulator
And as a starting base, I'm extending this implementation: http://www.stanford.edu/group/billiards/FastFiz/main.html
This is working really well except neither the paper nor the FastFiz implementation support or model the jaws of the pockets. Instead a ball is considered 'pocketed' when it enters the opening of the pocket boundary.
I am attempting to include the jaws as shown here:
(I need all the jaws, the image is just to show what I mean by 'jaws')
The event simulation uses gsl_poly_solve_quadratic from the GNU Scientific Library to calculate the time a collision with a rail or pocket will occur given the current state of a ball.
Due to my poor maths skills I can only express the situation in code rather than equations, I hope that is acceptable here.
For example the resulting code for a south rail collision is:
Code:
//South rail: y=0
numRoots = gsl_poly_solve_quadratic(-0.5 * mu * Table::g * u_hat.y, v.y, r.y - ball.getRadius(), &root1, &root2);
eventTime = calcEventTime(numRoots, root1, root2, curTime);
if (Utils::fgreater(eventTime, curTime)) //absolute(eventTime) > curTime + EPSILON)
{
t = eventTime - curTime;
collision_x = r.x +(v.x * t - 0.5 * mu * Table::g * u_hat.x * t * t);
if (collision_x < t_width -cp_width_real && collision_x > cp_width_real)
{
futureEvents.push_back(new RailCollisionEvent(eventTime, ball.getID(), Table::S_RAIL));
}
}
Where mu is the coefficient of friction, Table::g is gravity, u_hat is the velocity vector normal (when rolling) or "(v + (Vector(0, 0, 1).cross(ball.getSpin()) * ball.getRadius())).norm()" when sliding. v is the velocity vector and r is the current ball position.
And for the south west pocket would be:
Code:
//SW pocket
numRoots = gsl_poly_solve_quadratic(-0.5 * mu * Table::g * (u_hat.y + u_hat.x), v.x + v.y, r.x + r.y - cp_width - ball.getRadius(), &root1, &root2);
eventTime = calcEventTime(numRoots, root1, root2, curTime);
if (eventTime >= 0) {
futureEvents.push_back(new PocketedEvent(eventTime, ball.getID(), Table::SW));
}
Now it's trivial to move the pocket backwards deeper into the real pocket by removing the "- cp_width" from the quadratic, this works just fine, but I'm having enormous difficulty doing the same for the jaws in the pocket. I can get it to function but the collision events are not occurring anywhere near where the jaws should be.
For example, I've added two jaws to the south west pocket like so:
Code:
//SW pocket - N jaw
numRoots = gsl_poly_solve_quadratic(-0.5 * mu * Table::g * (u_hat.y + u_hat.x), v.x + v.y, r.x - r.y + cp_width - ball.getRadius(), &root1, &root2);
eventTime = calcEventTime(numRoots, root1, root2, curTime);
if(eventTime >= 0)
{
t = eventTime - curTime;
collision_x = r.x +(v.x * t - 0.5 * mu * Table::g * u_hat.x * t * t);
if (collision_x < 0)
{
collision_y = r.y + v.y * t - 0.5 * mu * Table::g * u_hat.y * t * t;
futureEvents.push_back(new RailCollisionEvent(eventTime, ball.getID(), Table::SWpNj));
}
}
//SW pocket - E jaw
numRoots = gsl_poly_solve_quadratic(-0.5 * mu * Table::g * (u_hat.y + u_hat.x), v.x + v.y, -r.x - r.y + cp_width - ball.getRadius(), &root1, &root2);
eventTime = calcEventTime(numRoots, root1, root2, curTime);
if(eventTime >= 0)
{
t = eventTime - curTime;
collision_x = r.x +(v.x * t - 0.5 * mu * Table::g * u_hat.x * t * t);
collision_y = r.y + v.y * t - 0.5 * mu * Table::g * u_hat.y * t * t;
if (collision_x < cp_width && collision_y <= 0)
{
futureEvents.push_back(new RailCollisionEvent(eventTime, ball.getID(), Table::SWpEj));
}
}
But this just doesn't work, the jaw rail collisions occur well behind the pockets and on the wrong angle.
Does anyone have any idea where I'm going wrong? Does what I'm doing even make sense?
I hope I haven't missed any relevant information here.
Again I apologise for my ignorance here.
Any assistance or guidance will be greatly appreciated.
Regards,
Lark.
Last edited: