Pool balls 'visible' from cue ball

Started by
7 comments, last by zdlr 20 years ago
Hello. I'm trying to figure out a way to calculate which pool balls are visible or not visible given a cue ball, a list of balls not valid to the player's turn and a list of balls that the player may hit this turn. This will be used in my game for aesthetic purposes (the player will be allowed to place a 'mask' over the table that will grey-out areas that cannot be reached directly without the use of cushions or English). Also, it could be used in the AI engine to prevent the computer from trying to hit a ball that is, for example, over a pocket when the black ball is in front of it and therefore blocking the shot. So this is what I am after and this is as far as I have progressed: Assume that the balls are represented by 3D particles with mass and a radius. This mass and radius are arbitrary as the user will be able to alter these settings. This calculation will only have to be made when all the balls are stationary so we only need position vectors and no kinematics are involved. Next, I realised that I need to 'draw' a vector that touches the cue ball tangentially on one side and *just misses* the blocking ball on it's opposite side, allowing the cue ball to pass it. I need two of these vectors per blocking ball so that for each blocking ball i have a pair of vectors that cross equidistant from the cue ball to the blocking ball (caveat: this is true only if the cue and blocking balls have to exact same radius). I then extend the two vectors from the blocking ball until they touch cushions (ie: table boundaries). The area between these two vectors and the blocking ball can then be greyed out or used in AI calculations. Here's a completely awful image to demonstrate my point (badly). This is equivalent to a pool player hunkering down and looking past the side of the cue ball to ensure (s)he can 'see' the ball they intend to hit. Ok, if you're still with me then I'll explain the problem I'm having. It's basically finding the vector that touches (tangentially) the white ball but narrowly misses the blocking ball. Narrowly missing the blocking ball is fairly easy as I just need to add my collision tolerance value to the radius of the blocking ball (note that once this is done the caveat mentioned above is active because the radii are not equal). I could brute force it and trace rays at every degree around the cue ball but this is hardly ideal nor desired as I am sure the answer to this question can be found. I wondered whether translating the vector between the cue ball and blocking ball so that it touches the radius of both would work. Simply do this twice, once for the 'left' side and once for the 'right' side of the cue ball/blocking ball, then swap the target values around to have crossing vectors. Sadly, the tangent from the right hand side of the cue ball to the right hand side of the blocking ball is different to the tangent from the right hand side of the cue ball to the left hand side of the blocking ball, albeit marginally. I'm afraid I cannot show you any code or screenies as yet because I haven't written a single line of code [edited by - zdlr on April 12, 2004 12:11:25 PM]
Advertisement
I can make a diagram to help you get started, but I dunno if I have a place to put the image or not.
Shoot Pixels Not People
email it to me at (gary at 4mm.co.uk) and i''ll post it here in a message after putting it on my website
Well if you you have balls a and b you can find the angle as a bearing at which a should be fired at to touch exactly the edge of b through this:

Find the bearing of the centre of b from the centre of a. Then to get the clockwise edge add
arcsin( radius*2 / distance between balls )
for the anticlockwise edge subtract this.

I think that should do the trick. There is probably a more computationally efficient method with vectors but this one works on paper.

To see if you can hit a ball past the blocking one you can compare the angles. If the angles to the blocking ball are wide enough to contain the angles to the ball to be hit then the ball cannot be hit.
This should give a good look of how it's done:

pool trig. if not shown, try later

As you can see, by either adding or subtracting acos(2r/d) to the angle of the line between the midpoints you get the angle to find the tangent.

Given this quick bit of explination and a picture to help visualize, it should be easy to do the rest.

(Sorry if my explination isn't very good. It's starting to get late here )

EDIT: Ooops.. looks like Drath beat me, and I accidentally put acos instead of asin

EDIT: What am I talking about? I was right the first time when I said arccos. (zdir: post the first image I sent you, it's the right one )


Shoot Pixels Not People


[edited by - drakonite on April 12, 2004 8:48:16 PM]
Shoot Pixels Not People
boom!

I hope that clears it up for you

TBH, if you can''t figure it out from here I have some bad news for you... A pool game is going to be very hard for you to do. You''d be amazed at just how much math like this is needed

Pool physics are not that simple. (Although I guess a simplified pool game is possible.. just not very realistic.)


Drakonite

Shoot Pixels Not People
Shoot Pixels Not People
Yeah but let's face it, I'm considering a fairly advanced feature such as this before writing a single line of code. Surely I deserve some kind of planning/design kudos - I've seen plenty of people berated on these forums for showing obvious signs of "jumping the gun" with regard to their abilities. I think I'm swimming at a steady pace rather than sinking.


[edited by - zdlr on April 12, 2004 9:02:49 PM]
Don''t get me wrong... I didn''t mean to berate you or anything like that. I have no idea of what your abilities are and I am not going to make comments about what you can or can''t do.

I simply meant it as a helpful comment, that at this point if the math for finding the tangents seems like greek, and you can''t figure out how to go from the angles to points on the circle, trying to make a pool sim will be a very rough ride as the majority of it will be this same type of math, but a bit more complex.
Shoot Pixels Not People

This topic is closed to new replies.

Advertisement