ATan2.htm 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. <html>
  2. <head>
  3. <title>Blitz3D Docs</title>
  4. <link rel=stylesheet href=../css/commands.css type=text/css>
  5. </head>
  6. <body>
  7. <h1>ATan2# ( y#, x# )</h1>
  8. <h1>Parameters</h1>
  9. <table>
  10. <tr>
  11. <td>
  12. y, x are any numbers. <br />
  13. <br />
  14. They are interpreted as corresponding to a point ( x, y ).
  15. </td>
  16. </tr>
  17. </table>
  18. <h1>Description</h1>
  19. <table>
  20. <tr>
  21. <td>
  22. ATan2 gives the angle between the positive x-axis and a vector from the point (0,0) to the point (x,y). <br />
  23. <br />
  24. One common use is in 2d graphics. Suppose you have two objects and you want to aim the first at the second. <br />
  25. <br />
  26. ATan2( y2 - y1, x2 - x1 ) gives the proper orientation for object1. <br />
  27. You can use this angle to select an appropriately rotated image. <br />
  28. <br />
  29. Notice the reverse order, ATan2( y, x ) rather than ATan2( x, y). <br />
  30. ATan2( y, x ) is analogous to ATan( y / x), but covers 360 degrees. <br />
  31. <br />
  32. The angle satisfies: -180 < ATan2 <= +180
  33. </td>
  34. </tr>
  35. </table>
  36. <h1><a href=../2d_examples/ATan2.bb>Example</a></h1>
  37. <table>
  38. <tr>
  39. <td>
  40. ; ATan2 example. <br />
  41. <br />
  42. ; Move mouse. Escape quits. <br />
  43. <br />
  44. Const width = 640, height = 480 <br />
  45. Const radius# = .2 * height <br />
  46. Const KEY_ESC = 1 <br />
  47. <br />
  48. Graphics width, height <br />
  49. SetBuffer BackBuffer( ) <br />
  50. Origin width / 2, height / 2 <br />
  51. HidePointer <br />
  52. MoveMouse .75 * width, height / 2 <br />
  53. <br />
  54. While Not KeyDown( KEY_ESC ) <br />
  55. <br />
  56. Cls <br />
  57. <br />
  58. Color 255, 255, 0 <br />
  59. Line 0, 0, width / 2, 0 ; positive x-axis <br />
  60. <br />
  61. x = MouseX() - width / 2 <br />
  62. y = MouseY() - height / 2 <br />
  63. <br />
  64. Oval x - 3, y - 3, 7, 7, True <br />
  65. Line 0, 0, x, y <br />
  66. <br />
  67. Text .35 * width, -80, "x = " + x <br />
  68. Text .35 * width, -60, "y = " + y <br />
  69. <br />
  70. Text .35 * width - 96, -40, "ATan2( y, x ) = " + ATan2( y, x ) <br />
  71. <br />
  72. Flip <br />
  73. <br />
  74. Wend <br />
  75. <br />
  76. End
  77. </td>
  78. </tr>
  79. </table>
  80. <br>
  81. <a target=_top href=../index.htm>Index</a><br>
  82. <br>
  83. Click <a href=http://www.blitzbasic.co.nz/b3ddocs/command.php?name=ATan2&ref=comments target=_blank>here</a> to view the latest version of this page online</body>
  84. </html>