# math.atan2

- **Ortam:** İstemci, Sunucu, Menü
- **İngilizce aslı:** https://wiki.facepunch.com/gmod/math.atan2
- **Çeviri tarihi:** 2025-09-08

```lua
number math.atan2( number y, number x )
```

## Açıklama

[math.atan](https://gmod.tr/wiki/math.atan)(y / x) gibi işlev görür, ancak açının bulunduğu çeyreği de hesaba kattığı için sınırlı bir çıktı aralığına sahip değildir.

> **NOT:** Y argümanı önce gelir!

## Argümanlar

1. [number](https://gmod.tr/wiki/number) **y**: Y koordinatı.
2. [number](https://gmod.tr/wiki/number) **x**: X koordinatı.

## Döndürülen Değer

1. [number](https://gmod.tr/wiki/number): (0, 0)'dan (x, y)'ye olan doğrunun (-pi, pi] sol-açık aralığındaki radyan cinsinden açısı.

### Örnek

atan( 1 ) ve atan2( 1, 1 )'nin ikisi de math.pi / 4 değerini verir.

atan2( -1, -1 ) ise ( (-3) * math.pi ) / 4 değerine eşittir.

```lua
print( atan( 1 ) )
print( atan2( 1, 1 ) )
print( atan2( -1, -1 ) )
```

**Çıktı:** 0.7853981633974483

0.7853981633974483

-2.356194490192345

### Örnek

Ekranın ortasına, imlecin konumuna göre dönen bir ikon çizer. **Not**: Bunu bir panelin içinde çizmek istiyorsanız [Panel:LocalCursorPos](https://gmod.tr/wiki/Panel:LocalCursorPos) kullanmanız gerekebilir.

```lua
local icon = Material("icon16/emoticon_smile.png", "smooth")
local iconSize = 64

hook.Add("HUDPaint", "Atan2Example", function()
	-- Açının hesaplanacağı göreceli nokta
	-- Buranın bizim "sıfır" koordinatımız olduğunu varsayabiliriz
	local centerX, centerY = ScrW()/2, ScrH()/2
	-- Açısını arayacağımız nokta
	local mouseX, mouseY = input.GetCursorPos()

	-- Açıyı radyan cinsinden al
	local angle = math.atan2(
		centerY - mouseY,
		mouseX - centerX
	)
	-- Dereceye çevir
	local deg = math.deg(angle)

	surface.SetDrawColor(255, 255, 255, 255)
	surface.SetMaterial(icon)
	surface.DrawTexturedRectRotated(centerX, centerY, iconSize, iconSize, deg)

	-- Sadece hata ayıklama için
	draw.SimpleText(deg, "DermaDefault", centerX, centerY + 40, color_white, TEXT_ALIGN_CENTER)
end)
```

- [GMod Wiki ana sayfası](https://gmod.tr/wiki)

---

[Tüm sunucular](https://gmod.tr/) · [GmodTR Launcher](https://gmod.tr/launcher) · [Rehber](https://gmod.tr/rehber) · [GMod Wiki](https://gmod.tr/wiki) · [GmodTR nedir?](https://gmod.tr/hakkinda) · [Sunucu ekle](https://gmod.tr/sunucu-ekle) · [Discord](https://discord.gg/gmodtr)

Kaynak: https://gmod.tr/wiki/math.atan2
