Pool/Billiards trig
ok i am trying to get a pool game going in c#/java.
start
= back of pool cue(x,y)end
= front of pool cue(x,y)circles
= list of balls (x,y,r)
So every time you move your mouse I update start
, end
and then I loop through `circles check if it intersects. Then this is my problem I need to figure out what will happen with ball if I hit it at the intersection point( will it go right up down).
How will I do this. I looked at some examples on google but could only find example where they did it with vector and that way over my head....
my first thought was get the angle of the pool cue and from the circle mid point draw a line the same angle but for some reason that is wrong. It might be my GetEnd
function
public Point GetEnd(Point start, double angle, int len)
{
d开发者_如何学Pythonouble y = start.Y + (len * Math.Sin(angle));
double x = start.X + (len * Math.Cos(angle));
return new Point((int)x, (int)y);
}
I think the angle between the direction where the cue points and the ball moves is:
Math.ASin(a/r)
with a
the minimal distance between the ray representing the cue and the center of the ball, and r
the radius of the ball.
You obtain a
by minimizing a^2 = (Cue.Position+Cue.Direction*Lamda-Ball.Position)^2
for lamda and then calculating the squareroot of that expression.
But I'm too lazy to reformulate that expressions without vectors.
精彩评论