OFFSIDE DEMONSTRATION APPLET


Instructions

  1. Place the mouse pointer over a player. Blue players are attacking the goal at the top of the screen, reds defending. Hold down the mouse button. Drag the player into any position on the pitch you fancy. Release the mouse button to drop the player in his current location. Repeat with as many players as you like.
  2. Click the 'Check for Offside' button. The red line represents the 'offside threshold' i.e. the point beyond which attacking players must not stray if they are to remain onside.
  3. The applet will either inform you of the (most) offside player, or describe the play as being onside.
  4. You also have the facility to draw arbitray shapes over the scene, a la Andy Gray on Sky Sports. To do this, click and drag the mouse without selecting a player to move. You are the pundit!
  5. If you are technically minded (or just curious, in all senses of the word...) you can see the Java source code on Github.
I wrote this applet following a conversation with a non-football savvy friend. I realised that the offside rule can seem complex when explained verbally, but very simple when illustrated graphically. According to the official rules of Association Football, the offside rule is thus:
  1. A player is in an offside position if he is nearer to his opponent's goal line than the ball is unless:
  2. A player will only be declared offside if, at the moment the ball touches or is played by one of his own team, in the opinion of the referee, that player is:
  3. A player will not be declared offside:
  4. If a player is declared offside, the referee gives an indirect free kick which is taken by the opposing team from the place where the offside occurred.Offside is judged from the moment the ball is played. A player who is level with the second last opponent or with the last two opponents is not in an offside position.

I thought this set of rules would be good to express in code - fun, and not too big an ask for a small personal project. If you want to see how it was done you can grab the code from Github.


Michael Fitzmaurice April, 2003