in reply to Code refactoring: simple trig, but it's been so long.

You can save some messing around with,     my $angle = atan2 $x2-$x1, $y2-$y1; I think that short-circuiting that is premature optimization, and may be an actual pessimization since FPU's do atan2 atomicly. Atan2 knows what quadrant the angle is in from the signs of its arguments, so you can save checking all those cases. Also, stick with radian measure except possibly for printed display.

Those together remove the need for Math::Trig.

After Compline,
Zaxo

Replies are listed 'Best First'.
Re^2: Code refactoring: simple trig, but it's been so long.
by revdiablo (Prior) on Dec 30, 2004 at 04:16 UTC

    Excellent. I didn't really like falling back to Math::Trig, and its dire performance warnings kind of worried me. This is a much simpler way to calculate the angle.