• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
sine and cosine functions
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

sine and cosine functions


  • Subject: sine and cosine functions
  • From: ehsan saffari <email@hidden>
  • Date: Fri, 27 Feb 2004 08:25:30 -0600

Here are native AS functions for sine & cosine, based on a Guidebook
module published by Apple. Input in degrees.

In my unscientific tests, they are faster than using the same functions
from 'Math' or 'More Math' osaxen.

They are also faster for very large values, in that they don't use a loop
to bring the input value to within (0,360) degrees

Not being a trig wiz, i hope someone can point out if i made any blatant
mistakes.

----------------------------
on cosine_of(x) -- degrees
if (x = 90) or (x = 270) then
set answer to 0
else
set x to (x - (((x / 360) div 1) * 360)) * (pi / 180)
set {answer, numerator, denominator, factor} to {0, 1, 1, -(x ^ 2)}
repeat with i from 2 to 40 by 2
set answer to answer + numerator / denominator
set numerator to numerator * factor
set denominator to denominator * i * (i - 1)
end repeat
end if
return answer
end cosine_of
----------------------------

----------------------------
on sine_of(x) -- degrees
if (x = 180) or (x = 360) then
set answer to 0
set x to (x - (((x / 360) div 1) * 360)) * (pi / 180)
set {answer, numerator, denominator, factor} to {0, x, 1, -(x ^ 2)}
repeat with i from 3 to 40 by 2
set answer to answer + numerator / denominator
set numerator to numerator * factor
set denominator to denominator * i * (i - 1)
end repeat
end if
return answer
end sine_of
----------------------------

cheers
ehsan

p.s hope boo can see this!
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.


  • Follow-Ups:
    • Re: sine and cosine functions
      • From: Emmanuel <email@hidden>
    • Re: sine and cosine functions
      • From: Doug McNutt <email@hidden>
    • Re: sine and cosine functions
      • From: Deivy Petrescu <email@hidden>
  • Prev by Date: Connection is Invalid
  • Next by Date: Re: Text to iPod
  • Previous by thread: Connection is Invalid
  • Next by thread: Re: sine and cosine functions
  • Index(es):
    • Date
    • Thread