mirror of
https://github.com/irmen/prog8.git
synced 2024-12-24 01:29:28 +00:00
rename math.atan() to math.atan2()
This commit is contained in:
parent
f56c12ee4e
commit
0aac9350d5
@ -254,7 +254,7 @@ _quadrant_region_to_direction:
|
||||
}}
|
||||
}
|
||||
|
||||
asmsub atan(ubyte x1 @R0, ubyte y1 @R1, ubyte x2 @R2, ubyte y2 @R3) -> ubyte @A {
|
||||
asmsub atan2(ubyte x1 @R0, ubyte y1 @R1, ubyte x2 @R2, ubyte y2 @R3) -> ubyte @A {
|
||||
;; Calculate the angle, in a 256-degree circle, between two points into A.
|
||||
;; The points (x1, y1) and (x2, y2) have to use *unsigned coordinates only* from the positive quadrant in the carthesian plane!
|
||||
;; https://www.codebase64.org/doku.php?id=base:8bit_atan2_8-bit_angle
|
||||
|
@ -187,7 +187,7 @@ math {
|
||||
sub direction(ubyte x1, ubyte y1, ubyte x2, ubyte y2) -> ubyte {
|
||||
; From a pair of positive coordinates, calculate discrete direction between 0 and 23 into A.
|
||||
; This adjusts the atan() result so that the direction N is centered on the angle=N instead of having it as a boundary
|
||||
ubyte angle = atan(x1, y1, x2, y2) - 256/48
|
||||
ubyte angle = atan2(x1, y1, x2, y2) - 256/48
|
||||
return 23-lsb(mkword(angle,0) / 2730)
|
||||
}
|
||||
|
||||
@ -226,14 +226,14 @@ sub direction_qd(ubyte quadrant, ubyte xdelta, ubyte ydelta) -> ubyte {
|
||||
}
|
||||
}
|
||||
|
||||
sub atan(ubyte x1, ubyte y1, ubyte x2, ubyte y2) -> ubyte {
|
||||
sub atan2(ubyte x1, ubyte y1, ubyte x2, ubyte y2) -> ubyte {
|
||||
;; Calculate the angle, in a 256-degree circle, between two points into A.
|
||||
;; The points (x1, y1) and (x2, y2) have to use *unsigned coordinates only* from the positive quadrant in the carthesian plane!
|
||||
%ir {{
|
||||
loadm.b r65532,math.atan.x1
|
||||
loadm.b r65533,math.atan.y1
|
||||
loadm.b r65534,math.atan.x2
|
||||
loadm.b r65535,math.atan.y2
|
||||
loadm.b r65532,math.atan2.x1
|
||||
loadm.b r65533,math.atan2.y1
|
||||
loadm.b r65534,math.atan2.x2
|
||||
loadm.b r65535,math.atan2.y2
|
||||
syscall 44 (r65532.b, r65533.b, r65534.b, r65535.b): r0.b
|
||||
returnr.b r0
|
||||
}}
|
||||
|
@ -384,7 +384,7 @@ but perhaps the provided ones can be of service too.
|
||||
Fast 8-bit byte cosine of angle 0..179 (each is a 2 degree step), result is in range -127..127
|
||||
Angles 180..255 will yield a garbage result!
|
||||
|
||||
``atan (ubyte x1, ubyte y1, ubyte x2, ubyte y2)``
|
||||
``atan2 (ubyte x1, ubyte y1, ubyte x2, ubyte y2)``
|
||||
Fast arctan routine that uses more memory because of large lookup tables.
|
||||
Calculate the angle, in a 256-degree circle, between two points in the positive quadrant.
|
||||
|
||||
|
@ -1,6 +1,12 @@
|
||||
%import math
|
||||
%import palette
|
||||
|
||||
; use the mouse to move the cursor around the screen
|
||||
; it uses the fast direction routine to spotlight your mouse position.
|
||||
|
||||
; you can use the atan2() routine as well for more precision laser beams,
|
||||
; but it will use a lot more memory due to the required lookup tables.
|
||||
|
||||
main {
|
||||
sub start() {
|
||||
const uword WIDTH=320
|
||||
|
Loading…
Reference in New Issue
Block a user