Microsoft provide an excellent SVG gradient maker so IE9 can also have \"CSS3\" gradients (click Custom).
I currently utilise their logic for my Fireworks and Dreamw
Instead of using Math.tan function You should use Math.atan2:
Here is an example of use:
deltaX = x2 - x1; deltaY = y2 - y1; deg = Math.atan2(deltaY, deltaX)*180.0/Math.PI;
and this will return a degree from <-180;180>.