Please check out the version I modified from the original one.
Now, you can rotate the magnet to any angle you want (including vertically).

What I did was make a transformation:
$x'=x \cos\theta+ y\sin\theta$
$y'=-x\sin\theta+ y\cos\theta$
for all the coordinates (magnet, compass, field)

The magnetic field is also transformed by
$B'_x=B_x \cos\theta-B_y \sin\theta$
$B'_y=B_x \sin\theta+B_y \cos\theta$

The following is a picture shows magnetic field structure of a magnet.
[img]http://upload.wikimedia.org/wikipedia/commons/thumb/5/57/Magnet0873.png/220px-Magnet0873.png[/img]

/htdocs/ntnujava/ejsuser/2/users/ntnu/fkh/MagneticBarFieldFKH3_pkg/MagneticBarFieldFKH3.propertiesFull screen applet or Problem viewing java?Add http://www.phy.ntnu.edu.tw/ to exception site list
Press the Alt key and the left mouse button to drag the applet off the browser and onto the desktop. This work is licensed under a Creative Commons Attribution 2.5 Taiwan License
Download EJS jar file(1144.5kB):double click downloaded file to run it. (6 times by 3 users) , Download EJS source (5 times by 3 users) View EJS source