OFFSIDE DEMONSTRATION APPLET
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,
offside rule is thus:
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.
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.
The applet will either inform you of the (most) offside player,
or describe the play as being onside.
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!
If you are technically minded (or just curious, in all senses
of the word...) you can
see the Java source code on Github.
- A player is in an offside position if he is nearer to his opponent's
goal line than the ball is unless:
- he is in his own half of the field
- he is not nearer to his opponent's goal-line than at least two of his opponents
- 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:
- interfering with the play or with an opponent, or
- seeking to gain an advantage by being in that position
- A player will not be declared offside:
- merely because of his being in an offside position, or
- if he receives the ball directly from a goal kick, corner kick, or throw-in
- 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