Last active
April 14, 2020 08:39
-
-
Save nonkit/69803f55bc4b871665d3aa75789d6804 to your computer and use it in GitHub Desktop.
Small Basic Pseudo Math Object
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sub Math_CartesianToPolar | |
' Math | convert Cartesian coodinate to polar coordinate | |
' param x, y - Cartesian coordinate | |
' return r, a - polar coordinate (0<=a<360) | |
r = Math.SquareRoot(x * x + y * y) | |
If x = 0 And y > 0 Then | |
a = 90 ' [degree] | |
ElseIf x = 0 And y < 0 Then | |
a = -90 | |
ElseIf x = 0 And y = 0 Then | |
a = 0 | |
Else | |
a = Math.ArcTan(y / x) * 180 / Math.Pi | |
EndIf | |
' at this point -90<=a<=90 | |
If x < 0 Then | |
a = a + 180 | |
ElseIf x >= 0 And y < 0 Then | |
a = a + 360 | |
EndIf | |
' at this point 0<=a<360 | |
EndSub |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sub Math_Dec2Hex | |
' Math | convert decimal to hexadecimal | |
' param dec - decimal number | |
' returns hex - hexadecimal text | |
Stack.PushValue("local", dec) | |
hex = "" | |
While 0 < dec | |
digit = Math.Remainder(dec, 16) | |
dec = Math.Floor(dec / 16) | |
hex = Text.Append(Text.GetSubText("0123456789ABCDEF", digit + 1, 1), hex) | |
EndWhile | |
If hex = "" Then | |
hex = "0" | |
EndIf | |
dec = Stack.PopValue("local") | |
EndSub |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sub Math_Hex2Dec | |
' Math | convert hexadecimal to decimal | |
' param hex | |
' returns dec | |
dec = 0 | |
len = Text.GetLength(hex) | |
For ptr = 1 To len | |
dec = dec * 16 + Text.GetIndexOf("123456789ABCDEF", Text.GetSubText(hex, ptr, 1)) | |
EndFor | |
EndSub |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Following code in
Math_CartesianToPolar
did not needed in SB 1.0 because SB 1.0 will not occur zero divided error.