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)
{
double 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:
with
athe minimal distance between the ray representing the cue and the center of the ball, andrthe radius of the ball.You obtain
aby minimizinga^2 = (Cue.Position+Cue.Direction*Lamda-Ball.Position)^2for lamda and then calculating the squareroot of that expression.But I’m too lazy to reformulate that expressions without vectors.