Difference between revisions of "ESM Math Library"

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! :))
Line 47: Line 47:
;S5 FUNCTION sqrt
;S5 FUNCTION sqrt
float sqr
float sqr
;S6 FUNCTION NormalizeAngle360
;S7 FUNCTION NormalizeAngle180


;S10 FUNCTION Hypotenuse
;S10 FUNCTION Hypotenuse
Line 136: Line 140:
set f.fin1 to myVarForInput
set f.fin1 to myVarForInput
setStage f 5
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.fout to f.fin1
else
  if f.fin1 < 0
    set f.fin1 to (f.fin1 + 360)
  else
    set f.fin1 to (f.fin1 - 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.fout to f.fin1
endif
if f.fout > 180
  set f.fout to (f.fout - 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>
set myResult to f.fout</pre>


Line 179: Line 228:
;Taylor Series Variant 1 - script by Galerion
;Taylor Series Variant 1 - script by Galerion


set f.ang to f.fin1
;CALL float NormalizeAngle180(float Angle)
 
setStage f 7
if f.ang < -180
set f.ang to f.fout
  set f.ang to (f.ang + 360)
elseif f.ang > 180
  set f.ang to (f.ang - 360)
endif


;approximate
;approximate
Line 210: Line 255:


set f.fout to f.sin
set f.fout to f.sin
if f.cos == 0
  set f.cos to 0.0001
endif
set f.fout2 to f.cos
set f.fout2 to f.cos
set f.fout3 to (f.sin/f.cos) ;tan</pre>
set f.fout3 to (f.sin/f.cos) ;tan</pre>
Line 241: Line 289:
;Taylor Series Variant 2 - script by JOG
;Taylor Series Variant 2 - script by JOG


set f.ang to f.fin1
;CALL float NormalizeAngle180(float Angle)
 
setStage f 7
if f.ang < -180
set f.ang to f.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.t1 to (f.ang*f.degToRad)
Line 257: Line 301:


set f.fout to f.sin
set f.fout to f.sin
if f.cos == 0
  set f.cos to 0.0001
endif
set f.fout2 to f.cos
set f.fout2 to f.cos
set f.fout3 to f.sin/f.cos ;tan</pre>
set f.fout3 to f.sin/f.cos ;tan</pre>
Line 285: Line 332:
;script by Galsiah
;script by Galsiah


set f.ang to f.fin1
;CALL float NormalizeAngle360(float Angle)
if f.ang < 0
setStage f 6
  set f.ang to (f.ang + 360)
set f.ang to (f.fout*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
set f.n to 1
Line 457: Line 500:
Code for the Stage Result Script:
Code for the Stage Result Script:
<pre>;FUNCTION float getAngle(float x, float y)
<pre>;FUNCTION float getAngle(float x, float y)
if f.fin1 == 0
  set f.fin1 to 0.001
endif
if f.fin2 == 0
  set f.fin2 to 0.001
endif


set f.tan to (f.fin1/f.fin2)
set f.tan to (f.fin1/f.fin2)
Anonymous user