Difference between revisions of "ESM Math Library"

Jump to navigation Jump to search
2,839 bytes added ,  16:43, 9 May 2006
YALU - Yet Another Layout Update
imported>JustTim
(fixed a bug in stage 21)
imported>JustTim
(YALU - Yet Another Layout Update)
If you've written such a function and you think it might be helpful to others, don't hesitate to contribute to this repository.
 
=== FirstStep Stepsby Step ===
To get this up and running follow there simple setup steps:
* Open any Plugin you wish or create a new one with the Construction Set
endif
End</pre>
This Quest Script already contains everything needed for the following functions.
 
 
=== Stage 5: Square Root ===
Based on [[Square_Root|Square Root]] Article
 
 
Code to include in FunctionQuestScript:
<pre>;S5 FUNCTION sqrt
float sqr</pre>
 
Code for the Stage Result Script:
<pre>;FUNCTION float sqrt(float input)
if (f.fin1 <= 0)
set f.fout to f.sqr
endif</pre>
 
Usage in another script:
<pre>;CALL float sqrt(float input)
set f.fin1 to myVarForInput
setStage f 5
set myResult to f.fout</pre>
 
=== Stage 10: Hypotenuse ===
Code to include in FunctionQuestScript:
<pre>;S10 FUNCTION Hypotenuse
float n</pre>
 
Code for the Stage Result Script:
<pre>;FUNCTION float Hypotenuse(float CathetusA, float CathetusB)
 
set f.n to ((f.fin1 * f.fin1) + (f.fin2 * f.fin2))
;FUNCTIONCALL float sqrt(float input)
set f.fin1 to f.n
setStage f 5
;fout is already the result</pre>
 
Usage in another script:
<pre>;CALL float Hypotenuse(float CathetusA, float CathetusB)
set f.fin1 to myVarForCathetusA
set f.fin2 to myVarForCathetusB
setStage f 10
set myResult to f.fout</pre>
 
=== Stage 15: Sin Cos Tan ===
Based on [[Trigonometry_Functions|Trigonometry Functions]] Article
 
 
Code to include in FunctionQuestScript:
<pre>;S15 FUNCTION SinCosTan
float ang
float sin
float cos
float exp</pre>
 
Code for the Stage Result Script:
<pre>;FUNCTION float,float,float SinCosTan(float Angle)
;Taylor Series Variant 1 - script by Galerion
set f.fout2 to f.cos
set f.fout3 to (f.sin/f.cos) ;tan</pre>
 
Usage in another script:
<pre>;CALL float,float,float SinCosTan(float Angle)
set f.fin1 to myVarForAngle
setStage f 15
set myResultSin to f.fout
set myResultCos to f.fout2
set myResultTan to f.fout3</pre>
 
=== Stage 16: Sin Cos Tan 2 ===
Based on [[Trigonometry_Functions|Trigonometry Functions]] Article
 
 
Code to include in FunctionQuestScript:
<pre>;S16 FUNCTION SinCodTan 2
float ang
float sin
float cos
float t1
float t2
float t5
float t6</pre>
 
Code for the Stage Result Script:
<pre>;FUNCTION float,float,float SinCosTan(float Angle)
;Taylor Series Variant 2 - script by JOG
set f.fout2 to f.cos
set f.fout3 to f.sin/f.cos ;tan</pre>
 
Usage in another script:
<pre>;CALL float,float,float SinCosTan(float Angle)
set f.fin1 to myVarForAngle
setStage f 16
set myResultSin to f.fout
set myResultCos to f.fout2
set myResultTan to f.fout3</pre>
 
=== Stage 20: Arcsine ===
Based on [[Trigonometry_Functions|Trigonometry Functions]] Article
 
 
Code to include in FunctionQuestScript:
<pre>;S20 FUNCTION Arcsine
float sin
float ang
float n</pre>
 
Code for the Stage Result Script:
<pre>;FUNCTION float Arcsine(float sin)
;Abramowitz/Stegun Approximation - script by JOG
 
set f.fout to f.rad*(1.5707963 - f.n*(1.5707288 - 0.2121144*f.sin+0.0742610*f.sin*f.sin - 0.0187293*f.sin*f.sin*f.sin))</pre>
 
Usage in another script:
<pre>;CALL float Arcsine(float sin)
set f.fin1 to myVarForSin
setStage f 20
set myResult to f.fout</pre>
 
=== Stage 21: Arcsine 2 ===
Based on [[Trigonometry_Functions|Trigonometry Functions]] Article
 
 
Code to include in FunctionQuestScript:
<pre>;S21 FUNCTION Arcsine 2
float t3
float t5
float t7</pre>
 
Code for the Stage Result Script:
<pre>;FUNCTION float Arcsine(float sin)
;Approximation by Taylor Series - script by DragoonWraith
 
set f.fout to (f.fin1 + (1/2)*(f.t3/3) + (3/8)*(f.t5/5) + (15/48)*(f.t7/7) )</pre>
 
Usage in another script:
<pre>;CALL float Arcsine(float sin)
set f.fin1 to myVarForSin
setStage f 21
set myResult to f.fout</pre>
 
=== Stage 22: Aroccosine ===
Based on [[Trigonometry_Functions|Trigonometry Functions]] Article
 
 
Code for the Stage Result Script:
<pre>;FUNCTION float Arccosine(float cos)
setStage f 20 ;Call Arcsine with same input
set f.fout to ((f.pi / 2) - f.fout)</pre>
 
Usage in another script:
<pre>;CALL float Arccosine(float cos)
set f.fin1 to myVarForCos
setStage f 22
set myResult to f.fout</pre>
 
=== Stage 23: Arccosine 2 ===
Based on [[Trigonometry_Functions|Trigonometry Functions]] Article
 
 
Code for the Stage Result Script:
<pre>;FUNCTION float Arccosine(float cos)
setStage f 21 ;Call Arcsine with same input
set f.fout to ((f.pi / 2) - f.fout)</pre>
 
Usage in another script:
<pre>;CALL float Arccosine(float cos)
set f.fin1 to myVarForCos
setStage f 23
set myResult to f.fout</pre>
 
=== Stage 24: Arctan ===
Based on [[Trigonometry_Functions|Trigonometry Functions]] Article
 
Code to include in FunctionQuestScript:
<pre>;S24 FUNCTION Arctan
float t3
float t5
float t7</pre>
 
Code for the Stage Result Script:
<pre>;FUNCTION float Arctan(float tan)
;Approximation by Taylor Series - script by DragoonWraith
 
set f.fout to (f.fin1 - (f.t3/3) + (f.t5/5) - (f.t7/7))</pre>
 
Usage in another script:
<pre>;CALL float Arctan(float tan)
set f.fin1 to myVarForTan
setStage f 24
set myResult to f.fout</pre>
 
=== Stage 30: getAngle ===
Code to include in FunctionQuestScript:
<pre>;S30 FUNCTION getAngle
float tan
float ang</pre>
 
Code for the Stage Result Script:
<pre>;FUNCTION float getAngle(float x, float y)
 
endif
 
;CALL float Arctan(float tan)
set f.fin1 to f.tan
setStage f 24 ;Call Arctan
 
if f.fout > (f.pi/2)
endif
set f.fout to ((f.fout*f.rad) + f.ang)</pre>
 
Usage in another script:
<pre>;CALL float getAngle(float x, float y)
set f.fin1 to myVarForX
set f.fin2 to myVarForY
setStage f 30
set myResultAngle to f.fout</pre>
 
[[Category: Scripting]]
Anonymous user

Navigation menu