The ATAN2 function appears to missing.
a = 0.5
b = -0.765
c = atan2(a, b)
PRINT "c = ", c
END
Start program
No such variable line # 5
ATAN2 missing?
-
- Posts: 37
- Joined: Thu Nov 01, 2012 10:57 am
- Location: Johannesburg, South Africa
Re: ATAN2 missing?
Agree. I've got Control BASIC v0.79. Gives the same error!
-
- Posts: 37
- Joined: Thu Nov 01, 2012 10:57 am
- Location: Johannesburg, South Africa
Re: ATAN2 missing?
ATAN2 was first implemented in the Control BASIC v0.75 firmware.
I therefore tested ATAN2 with the following firmware versions:
Control BASIC v0.75
Control BASIC v0.76
Control BASIC v0.77
Control BASIC v0.78
Control BASIC v0.79
Control BASIC v0.80
I can confirm that ATAN2 ONLY works in the Control BASIC v0.75 firmware and NONE of the subsequent firmware versions up to v0.80.
Maybe Daniel can help here!
Regards
Andries Pretorius
I therefore tested ATAN2 with the following firmware versions:
Control BASIC v0.75
Control BASIC v0.76
Control BASIC v0.77
Control BASIC v0.78
Control BASIC v0.79
Control BASIC v0.80
I can confirm that ATAN2 ONLY works in the Control BASIC v0.75 firmware and NONE of the subsequent firmware versions up to v0.80.
Maybe Daniel can help here!
Regards
Andries Pretorius
Re: ATAN2 missing?
Here's a four quadrant inverse tangent subroutine named ATAN3. It determines angles between 0 and 2 PI radians.
Here are the results from the demo;
Start program
user-defined angle = 222.25678 degrees
a = -0.672454395
b = -0.7401385589
angle from ATAN3 = 222.25678 degrees
Program Ended.
Code: Select all
' demo_atan3.bas
' June 24, 2015
' demonstrates how to intereact with the ATAN3 subroutine
dtr = PI / 180.0
rtd = 180.0 / PI
angle_deg = 222.25678
' convert angle to radians
angle_rad = dtr * angle_deg
' compute sin and cosine of angle
a = sin(angle_rad)
b = cos(angle_rad)
' call four quadrant inverse tangent
GOSUB ATAN3:
' print results
print " "
print "user-defined angle = ", angle_deg, " degrees"
print " "
print "a = ", a
print "b = ", b
print " "
print "angle from ATAN3 = ", rtd * c, " degrees"
END
ATAN3:
' four quadrant inverse tangent function
' input
' a = sine of angle
' b = cosine of angle
' output
' c = angle (0 =< c <= 2 * pi : radians)
'''''''''''''''''''''''''''''''''''''''''
pidiv2 = PI / 2.0
x = a
GOSUB SIGN:
sgn_a = sgn
x = b
GOSUB SIGN:
sgn_b = sgn
IF (ABS(a) < 1.0e-10) THEN
c = (1.0 - sgn_b) * pidiv2
RETURN
ELSE
c = (2.0 - sgn_a) * pidiv2
ENDIF
IF (ABS(b) < 1.0e-10) THEN
RETURN
ELSE
c = c + sgn_a * sgn_b * (ABS(ATAN(a / b)) - pidiv2)
ENDIF
RETURN
'''''''''''''''
'''''''''''''''
SIGN:
' sign of a variable subroutine
' input
' x = argument
' output
' sgn = sign of x
''''''''''''''''''
IF (x > 0.0) THEN
sgn = 1.0
ENDIF
IF (abs(x) <= 1.0e-12) THEN
sgn = 0.0
ENDIF
IF (x < 0.0) THEN
sgn = -1.0
ENDIF
RETURN
Start program
user-defined angle = 222.25678 degrees
a = -0.672454395
b = -0.7401385589
angle from ATAN3 = 222.25678 degrees
Program Ended.