flat assembler
Message board for the users of flat assembler.

Index > Tutorials and Examples > Azimuth To Cartesian (decimal 0..360)

Author
Thread Post new topic Reply to topic
idle



Joined: 06 Jan 2011
Posts: 440
Location: Ukraine
idle 16 Nov 2023, 19:22
Hi, sometimes crucially needed, posting...
Code:
;2023.11.05
;use i586


;Cartesian Circle °      Azimuth Circle °
;x--                     x++
;y++                     y--
;
;
;          y 90°                   y 
;          |.cos.                  |
;          |    .   +++            |..cos..  ++
;          |   sin   ++            |     sin +++
;          |    .                  |      .
;  --------0-------x     --------0-------x 90°
;          |                       |
;          |                       |
;          |                       |
;          |                       |


;azimuth(decimal angle) -> st0 <- cartesian(decimal angle 0..360)
;flags.cf <- st0 > 180
;st1 used
azimuth2cartesian:
        fild   [.360]
        fxch
        fprem
        fstp   st1               ;mod 360

        fld    [.mul_pi_div_180]
        fmulp                    ;in rad

        fsincos                  ;azimuth   x,y
        fxch                     ;cartesian x,y

        fpatan                   ;x,y -> rad

        fld     [.mul_180_div_pi]
        fmulp                    ;deg

        fldz                     ;fpatan gives [-180..0..180] results, that is why PATRIAL; so make values absolute ie 0..360
        fcomip  st0,st1          ;i586
        jb      .ret             ;0..180
        fiadd   [.360]

  .ret: ret

align 4
  .360            dw 360
  .mul_pi_div_180 dt 0.0174532925199432958
  .mul_180_div_pi dt 57.295779513082320880
    
Post 16 Nov 2023, 19:22
View user's profile Send private message Reply with quote
tthsqe



Joined: 20 May 2009
Posts: 767
tthsqe 17 Nov 2023, 04:14
is this a Rube Goldburg function for calculating (90-st0) mod 360?
Post 17 Nov 2023, 04:14
View user's profile Send private message Reply with quote
idle



Joined: 06 Jan 2011
Posts: 440
Location: Ukraine
idle 17 Nov 2023, 06:36
Az135° (South-East) ?
Post 17 Nov 2023, 06:36
View user's profile Send private message Reply with quote
idle



Joined: 06 Jan 2011
Posts: 440
Location: Ukraine
idle 17 Nov 2023, 06:44
...
-45 [+360=315]
...
omg
true
😄
Post 17 Nov 2023, 06:44
View user's profile Send private message Reply with quote
idle



Joined: 06 Jan 2011
Posts: 440
Location: Ukraine
idle 17 Nov 2023, 09:21
Code:
;2023.11.17 tthsqe mod Smile
;2023.11.05
;use i586


;Cartesian Circle °      Azimuth Circle °
;x--                     x++
;y++                     y--
;
;
;          y 90°                   y 
;          |.cos.                  |
;          |    .   +++            |..cos..  ++
;          |   sin   ++            |     sin +++
;          |    .                  |      .
;  --------0-------x     --------0-------x 90°
;          |                       |
;          |                       |
;          |                       |
;          |                       |


;https://board.flatassembler.net/topic.php?t=23112
;tthsqe "is this a Rube Goldburg function for calculating (90-st0) mod 360?"
;... haha ... omg ... elegant ... tnx!!!
azimuth2cartesian:
        fild    [.360]
        fxch
        fprem
        fstp    st1

        fisubr  [.090]

        fldz
        fcomip  st0,st1
        jb      .ret
        fiadd   [.360]

  .ret: ret

align 4
  .360 dw 360
  .090 dw 090


;azimuth(decimal angle) -> st0 <- cartesian(decimal angle 0..360)
;flags.cf <- st0 > 180
;st1 used
;azimuth2cartesian:
;        fild   [.360]
;        fxch
;        fprem
;        fstp   st1               ;mod 360
;
;        fld    [.mul_pi_div_180]
;        fmulp                    ;in rad
;
;        fsincos                  ;azimuth   x,y
;        fxch                     ;cartesian x,y
;
;        fpatan                   ;x,y -> rad
;
;        fld     [.mul_180_div_pi]
;        fmulp                    ;deg
;
;        fldz                     ;fpatan gives [-180..0..180] results, that is why PATRIAL; so make values absolute ie 0..360
;        fcomip  st0,st1          ;i586
;        jb      .ret             ;0..180
;        fiadd   [.360]
;
;  .ret: ret
;
;align 4
;  .360            dw 360
;  .mul_pi_div_180 dt 0.0174532925199432958
;  .mul_180_div_pi dt 57.295779513082320880
    
Post 17 Nov 2023, 09:21
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.