85 lines
2.1 KiB
HTML
85 lines
2.1 KiB
HTML
<html>
|
|
<head>
|
|
<title>Blitz3D Docs</title>
|
|
<link rel=stylesheet href=../css/commands.css type=text/css>
|
|
</head>
|
|
<body>
|
|
<h1>ATan2# ( y#, x# )</h1>
|
|
<h1>Parameters</h1>
|
|
<table>
|
|
<tr>
|
|
<td>
|
|
y, x are any numbers.
|
|
<br />
|
|
<br />
|
|
They are interpreted as corresponding to a point ( x, y ).
|
|
</td>
|
|
</tr>
|
|
</table>
|
|
<h1>Description</h1>
|
|
<table>
|
|
<tr>
|
|
<td>
|
|
ATan2 gives the angle between the positive x-axis and a vector from the point (0,0) to the point (x,y).
|
|
|
|
<br />
|
|
|
|
<br />
|
|
One common use is in 2d graphics. Suppose you have two objects and you want to aim the first at the second.
|
|
|
|
<br />
|
|
|
|
<br />
|
|
ATan2( y2 - y1, x2 - x1 ) gives the proper orientation for object1.
|
|
|
|
<br />
|
|
You can use this angle to select an appropriately rotated image.
|
|
|
|
<br />
|
|
|
|
<br />
|
|
Notice the reverse order, ATan2( y, x ) rather than ATan2( x, y).
|
|
|
|
<br />
|
|
ATan2( y, x ) is analogous to ATan( y / x), but covers 360 degrees.
|
|
|
|
<br />
|
|
|
|
<br />
|
|
The angle satisfies: -180 < ATan2 <= +180
|
|
</td>
|
|
</tr>
|
|
</table>
|
|
<h1><a href=../2d_examples/ATan2.bb>Example</a></h1>
|
|
<table>
|
|
<tr>
|
|
<td>
|
|
; ATan2 example.
|
|
<br />
|
|
|
|
<br />
|
|
; Move mouse. Escape quits.
|
|
<br />
|
|
|
|
<br />
|
|
Const width = 640, height = 480
|
|
<br />
|
|
Const radius# = .2 * height
|
|
<br />
|
|
Const KEY_ESC = 1
|
|
<br />
|
|
|
|
<br />
|
|
Graphics width, height
|
|
<br />
|
|
SetBuffer BackBuffer( )
|
|
<br />
|
|
Origin width / 2, height / 2
|
|
<br />
|
|
HidePointer
|
|
<br />
|
|
MoveMouse .75 * width, height / 2
|
|
<br />
|
|
|
|
<br />
|
|
While Not KeyDown( KEY_ESC )
|
|
<br />
|
|
|
|
<br />
|
|
Cls
|
|
<br />
|
|
|
|
<br />
|
|
Color 255, 255, 0
|
|
<br />
|
|
Line 0, 0, width / 2, 0 ; positive x-axis
|
|
<br />
|
|
|
|
<br />
|
|
x = MouseX() - width / 2
|
|
<br />
|
|
y = MouseY() - height / 2
|
|
<br />
|
|
|
|
<br />
|
|
Oval x - 3, y - 3, 7, 7, True
|
|
<br />
|
|
Line 0, 0, x, y
|
|
<br />
|
|
|
|
<br />
|
|
Text .35 * width, -80, "x = " + x
|
|
<br />
|
|
Text .35 * width, -60, "y = " + y
|
|
<br />
|
|
|
|
<br />
|
|
Text .35 * width - 96, -40, "ATan2( y, x ) = " + ATan2( y, x )
|
|
<br />
|
|
|
|
<br />
|
|
Flip
|
|
<br />
|
|
|
|
<br />
|
|
Wend
|
|
<br />
|
|
|
|
<br />
|
|
End
|
|
</td>
|
|
</tr>
|
|
</table>
|
|
<br>
|
|
<a target=_top href=../index.htm>Index</a><br>
|
|
<br>
|
|
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>
|
|
</html>
|