Beefy Boxes and Bandwidth Generously Provided by pair Networks httptech
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

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

by tachyon (Chancellor)
on Dec 29, 2004 at 21:08 UTC ( [id://418156]=note: print w/replies, xml ) Need Help??

This is an archived low-energy page for bots and other anonmyous visitors. Please sign up if you are a human and want to interact.


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

Evidently you feel more comfortable using degrees rather than radians but the conversion to and from radians<->degrees serves no real purpose. Just define:

my $ninety_degrees = atan(1)*2;

You will get a division by zero crash in the case where $x and $y = 0 as it will fall through your 'extreme cases'. You can remove the dependency on a module by using radians and using a function for atan() like:

sub atan { return 0 if $_[0]==0; return $_[0] > 0 ? atan2(sqrt(1+$_[0]*$_[0]),sqrt(1+1/($_[0]*$_[0]))) : -atan2(sqrt(1+$_[0]*$_[0]),sqrt(1+1/($_[0]*$_[0]))); }

cheers

tachyon

Replies are listed 'Best First'.
Re^2: Code refactoring: simple trig, but it's been so long.
by revdiablo (Prior) on Dec 29, 2004 at 23:27 UTC
    Evidently you feel more comfortable using degrees rather than radians but the conversion to and from radians<->degrees serves no real purpose.

    Yeah, that was just out of habit. I noticed that the conversion between radians and degrees was pointless before I posted, but never got around to changing it to only radians.

    You will get a division by zero crash in the case where $x and $y = 0 as it will fall through your 'extreme cases'.

    Ah, I hadn't noticed that. Using Zaxo's code will eliminate that problem, though. Many thanks.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://418156]
help
Sections?
Information?
Find Nodes?
Leftovers?
    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.