Nov 99 Challenge
Volume Number: 15
Issue Number: 11
Column Tag: Programmer's Challenge
Programmer's Challenge
by Bob Boonstra, Westford, MA
Putting Green
I'll confess. While I'm as much of a sports fan as the next guy, I've never been able to
get excited about golf. Not playing it, except maybe a round of miniature golf while on
vacation each summer. Not watching it, which is the closest thing to watching grass
grow that I can imagine. In fact, I have a hard time even thinking of golf as a sport.
Real sports involve perspiration. Real sports involve being exhausted. Golf doesn't
have either, as near as I have been able to tell, and therefore couldn't be worth getting
involved in. Or so I thought.
Feeling this way, I didn't pay very much attention to the news that the 1999 Ryder Cup
was going to be held relatively close by. And, when a ticket to the first day of matches
came my way, I thought about passing it on to someone else. For a few days, that is.
Until I started reading some of the growing volume of newspaper coverage and got an
appreciation for what a really big deal people were making of this. It seemed even
bigger than the baseball All Star game, also held in Boston this year. Baseball, also not
the most intense sport, involves some amount of running and perspiration. So if the
Ryder Cup was as big as the All Star game, it must be worth watching. So I decided to
attend.
What, you must be asking, does any of this have to do with the Programmer's
Challenge? Did someone substitute an issue of Sports Illustrated under the cover? No,
it's just that the Ryder Cup provided the inspiration for this month's Challenge.
Watching Tiger Woods make a birdie putt on the 10th, watching three teams miss
essentially the same putt on the 14th, my mind turned to - why, physics, of course.
How did they read (or misread) those breaks? Your Challenge will be to figure it out.
The Challenge this month is going to be to put some simulated balls into simulated holes
on simulated greens. The greens will be provided to you as an array of three
dimensional points, divided into an array of adjoining triangles. You will "putt" the
ball by imparting a velocity. The ball will move according to a black box propagation
model that incorporates the effects of gravity and drag. How are you supposed to know
how the ball will move if you don't have the propagation code? The same way Tiger and
Monty do it, of course - practice!
The prototype for the code you should write is:
#if defined(__cplusplus)
extern "C" {
#endif
#include
typedef struct Point3DDouble {
double x;
double y;
double z;
} Point3DDouble;
typedef struct Velocity2DDouble {
double x;
double y;
} Velocity2DDouble;
typedef struct MyTriangle {
long pointIndices[3]; /* index of points comprising the triangle
*/
} MyTriangle;
typedef struct BallPosition {
double time;
Point3DDouble pt;
} BallPosition;
void InitGreen(
Point3DDouble points[], /* green terrain description */
long numPoints, /* number of points */
MyTriangle triangles[], /* triangles comprising the green */
int numTriangles, /* number of triangles */
long pinTriangle, /* index in triangles[] of the pin on this
green */
long numPracticeHoles,
/* number of unscored (but timed) holes to practice on
this green */
long numScoredHoles /* number of holes to be scored on this
green */
);

void StartHole( /* called to start play on this hole */
Point3DDouble ballPosition, /* initial ball position on the green */
Boolean practice /* TRUE if this hole is practice */
);
Boolean /* quit */ MakePutt(
Velocity2DDouble *xyVelocity
/* return initial ball velocity in the z==0 plane */
);
void BallMovement(
BallPosition ballPositions[],
/* provides ball movement in response to MakePutt
*/
int numBallPositions, /* number of ballPositions provided */
Boolean inHole /* true if the ball went into the hole */
);
#if defined(__cplusplus)
}