flat assembler
Message board for the users of flat assembler.

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

Joined: 06 Jan 2011
Posts: 439
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 0°
;          |.cos.                  |
;          |    .   +++            |..cos..  ++
;          |   sin   ++            |     sin +++
;          |    .                  |      .
;  --------0-------x 0°    --------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]

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

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

.ret: ret

align 4
.360            dw 360
.mul_pi_div_180 dt 0.0174532925199432958
.mul_180_div_pi dt 57.295779513082320880
```
16 Nov 2023, 19:22
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?
17 Nov 2023, 04:14
idle

Joined: 06 Jan 2011
Posts: 439
Location: Ukraine
idle 17 Nov 2023, 06:36
Az135° (South-East) ?
17 Nov 2023, 06:36
idle

Joined: 06 Jan 2011
Posts: 439
Location: Ukraine
idle 17 Nov 2023, 06:44
...
-45 [+360=315]
...
omg
true
😄
17 Nov 2023, 06:44
idle

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

;Cartesian Circle °      Azimuth Circle °
;x--                     x++
;y++                     y--
;
;
;          y 90°                   y 0°
;          |.cos.                  |
;          |    .   +++            |..cos..  ++
;          |   sin   ++            |     sin +++
;          |    .                  |      .
;  --------0-------x 0°    --------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

.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]
;
;        fsincos                  ;azimuth   x,y
;        fxch                     ;cartesian x,y
;
;
;        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
;
;  .ret: ret
;
;align 4
;  .360            dw 360
;  .mul_pi_div_180 dt 0.0174532925199432958
;  .mul_180_div_pi dt 57.295779513082320880
```
17 Nov 2023, 09:21
 Display posts from previous: All Posts1 Day7 Days2 Weeks1 Month3 Months6 Months1 Year Oldest FirstNewest First

 Jump to: Select a forum Official----------------AssemblyPeripheria General----------------MainTutorials and ExamplesDOSWindowsLinuxUnixMenuetOS Specific----------------MacroinstructionsOS ConstructionIDE DevelopmentProjects and IdeasNon-x86 architecturesHigh Level LanguagesProgramming Language DesignCompiler Internals Other----------------FeedbackHeapTest Area

Forum Rules:
 You cannot post new topics in this forumYou cannot reply to topics in this forumYou cannot edit your posts in this forumYou cannot delete your posts in this forumYou cannot vote in polls in this forumYou cannot attach files in this forumYou can download files in this forum