# Baseball Physics

This topic is 3800 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hey there, I'm a relatively new programmer with a relatively small project: I need to create a physics engine for a baseball being hit on a field. For example: power, direction (x,y), and angle (z) would be given and then it would show the ball being hit and where it would bounce, etc. Graphics are not really important here, I just need to be able to set up something that is visual simulation. Is there a really easy way to do this, or any tools I could use that would simplify this? Thanks so much!

##### Share on other sites
It could be something extremely simple, e.g., a particle-based engine in which you just track the center-of-mass of the ball and do collision detection of a sphere with planes (swept-sphere vs. ground plane (and possibly batter's cage?). There's open source code available that will give you code for swept-sphere vs. plane collision detection (for example see Dave Eberly's Geometric Tools site...capped cylinder vs. plane). The dynamics of the ball between collisions is very straightforward, and unless you are worried about a semi-accurate response of the bat hitting the ball, you could just apply a simple impulse to the ball to represent the bat hit. I personally wouldn't bother using a full physics engine such as Bullet or ODE for this, but whether you are comfortable writing something yourself would depend on your comfort level with very basic particle physics and collision detection. Aerodynamic drag is easy to calculate and apply, as is, of course, the weight of the ball.

If you need to represent the rotational effects...that is a bit more work. You don't probably need to simulate rotational dynamics for a baseball sim (which is part of the reason why I suggest not bothering with a full physics engine), but if you want to include a represent of Magnus force, an aerodynamic force that arises due to spin, then it'd be a bit more work but still could be done with a particle system. My GDC 2006 talk and Game Programming Gems 5 book article discuss this briefly...

If you're a novice to physics programming in general, you might want to look at the introductory presentations on game physics at Jim van Verth's Essential Math site. (See the sticky thread on physics engines within this forum for a link to that.)

##### Share on other sites
Thanks for all the info...wow.
EDIT: The more I read your post grhodes, the more what you are saying makes sense! I just need to fidget with these things you suggested a little bit.

Anyway, I have just completed writing C++ code that calculates all the basic components of projectile motion (which is basically what hitting a baseball is) when the user inputs an angle and initial velocity.

Since eventually I will want to have simuated fielders that would interact with the ball, would a collision engine be able to help me with that? (i.e. the ball colliding with a defined space that is the fielder, say 3 ft radius; the collision would result in the fielder catiching it.) Or are the collision engines more useful for the ball bouncing after it hits the ground or ricocheting off of the wall?

I guess I don't really need to implement a complete physics engine. In fact, I really only need to be able to visually represent the ball's path (which my simple program can already define at any time interval, say every 0.1 seconds). Once I get a basis down, then I can work on more complex things like rotational spin (actually VERY important on a hit baseball). Is there a program that can help me visually show the path of the ball on a 2D field, say, from a bird's eye perspective? In essence, it would only be drawing a straight line with maybe a larger ball graphic for the ball when it is at a higher height, so the player can actually SEE the ball getting higher rather than it just drawing a flat, straight line. I hope I explained well what I'm trying to get at! Basically, I'm struggling with developing an actual visual for what is going on. Thanks for your response!

##### Share on other sites
I don't think I'd bother with a full collection detection system for this simple problem. Let the fielders' gloves be represented by spheres of some radius larger than the glove, and if the center of the glove touches a time-swept sphere for the ball with radius = (radius_of_ball + radius_of_glove) during a time step, then call it a catch. (This idea of shrinking the glove to a point and growing the ball's time-swept sphere by the glove's radius is based on the concept of the Minkowski Sum, which is a concept used heavily in formal collision detection. I think you need the swept sphere to deal with ball speed and frame rate variations...essentially you're doing simple "continuous collision detection" (CCD), but I don't think you necessarily need to use a full collision detection system to do it for this type of game. (Dave Eberly might also have code for a capsule vs. sphere test...I know he has a capsule vs. line test---these two can be converted back and forth rather easily, either of which you could just use outright...just that part of a collision detection system.)

If you do want to use an existing collision detection system, then I'd recommend looking into Bullet's CCD system. That CCD system can be used without using Bullet physics...it's a separate module. And it's open source.

##### Share on other sites
Oh, I should say that most proper collision detection systems can be used for proximity checks also. The bouncing/stacking/sliding (collision response) is handled by the physics side. The collision detection system just computes contact points + contact normals (needed to compute bounce, etc.) and/or geometric intersections, which is more what you'd want for catching the ball. The systems usually allow you to register a callback function that would notify your code when, say, the capsule swept out by the ball over a frame intersects the sphere around the fielder's glove.

1. 1
Rutin
45
2. 2
3. 3
4. 4
5. 5
JoeJ
19

• 13
• 10
• 12
• 10
• 13
• ### Forum Statistics

• Total Topics
632998
• Total Posts
3009811
• ### Who's Online (See full list)

There are no registered users currently online

×