Difference between revisions of "ESM Math Library"

Jump to navigation Jump to search
1,234 bytes added ,  14:05, 18 May 2006
added stage 6 & 7 - 2 functions to normalize angles - STAGE 6 IS A REAL LOOP! :)
imported>Galsiah
imported>JustTim
(added stage 6 & 7 - 2 functions to normalize angles - STAGE 6 IS A REAL LOOP! :))
;S5 FUNCTION sqrt
float sqr
 
;S6 FUNCTION NormalizeAngle360
 
;S7 FUNCTION NormalizeAngle180
 
;S10 FUNCTION Hypotenuse
set f.fin1 to myVarForInput
setStage f 5
set myResult to f.fout</pre>
 
=== Stage 6: Normalize Angle (0 till 360) ===
Takes an Angle and normalizes it to a range from 0 to 360 degrees.
This is a functional loop!
 
Code for the Stage Result Script:
<pre>;FUNCTION float NormalizeAngle360(float Angle)
if (f.fin1 >= 0) && (f.fin1 <= 360)
set f.angfout to f.fin1▼
else
if f.angfin1 < 0▼
set f.angfin1 to (f.angfin1 + 360)▼
else
set f.angfin1 to (f.angfin1 - 360)▼
endif▼
;CALL float NormalizeAngle360(float angle)
setStage f 6
endif</pre>▼
 
Usage in another script:
<pre>;CALL float NormalizeAngle360(float angle)
set f.fin1 to myVarForAngle
setStage f 6
set myResult to f.fout</pre>
 
=== Stage 7: Normalize Angle (-180 till 180) ===
Takes an Angle and normalizes it to a range from -180 to 180 degrees.
 
Code for the Stage Result Script:
<pre>;FUNCTION float NormalizeAngle180(float Angle)
if (f.fin1 < 0) || (f.fin1 > 360)
;CALL float NormalizeAngle360(float Angle)
setStage f 6
else
set f.angfout to f.fin1▼
endif▼
elseifif f.angfout > 180▼
set f.angfout to (f.angfout - 360)▼
endif</pre>
 
Usage in another script:
<pre>;CALL float NormalizeAngle180(float angle)
set f.fin1 to myVarForAngle
setStage f 7
set myResult to f.fout</pre>
 
;Taylor Series Variant 1 - script by Galerion
 
;CALL float NormalizeAngle180(float Angle)
▲set f.ang to f.fin1
setStage f 7
 
ifset f.ang <to -180f.fout
▲ set f.ang to (f.ang + 360)
▲elseif f.ang > 180
▲ set f.ang to (f.ang - 360)
▲endif
 
;approximate
 
set f.fout to f.sin
if f.cos == 0
set f.angcos to f0.fin10001▼
endif
set f.fout2 to f.cos
set f.fout3 to (f.sin/f.cos) ;tan</pre>
;Taylor Series Variant 2 - script by JOG
 
;CALL float NormalizeAngle180(float Angle)
▲set f.ang to f.fin1
setStage f 7
 
ifset f.ang <to -180f.fout
set f.ang to f.ang + 360
elseif f.ang > 180
set f.ang to f.ang - 360
▲endif
 
set f.t1 to (f.ang*f.degToRad)
 
set f.fout to f.sin
if f.cos == 0
▲ set f.angcos to f0.ang + 3600001
endif
set f.fout2 to f.cos
set f.fout3 to f.sin/f.cos ;tan</pre>
;script by Galsiah
 
;CALL float NormalizeAngle360(float Angle)
▲set f.ang to f.fin1
setStage f 6
▲if f.ang < 0
set f.ang to (f.ang + 360fout*f.degToRad)
elseif f.ang >= 360
▲ set f.ang to (f.ang - 360)
▲endif
set f.ang to (f.ang*f.degToRad)
 
set f.n to 1
Code for the Stage Result Script:
<pre>;FUNCTION float getAngle(float x, float y)
 
if f.fin1 == 0
▲ set f.angfin1 to f0.ang - 360001
endif
if f.fin2 == 0
set f.fin2 to 0.001
endif
 
set f.tan to (f.fin1/f.fin2)
Anonymous user

Navigation menu