Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: Code refactoring: simple trig, but it's been so long.

by Zaxo (Archbishop)
on Dec 30, 2004 at 02:02 UTC ( [id://418155]=note: print w/replies, xml ) Need Help??


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.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://418155]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (4)
As of 2024-04-20 00:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found