Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
ゲーム制作に活かす座標系の話
Search
Sponsored
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
Ark
January 17, 2018
Programming
500
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
ゲーム制作に活かす座標系の話
Tokyotech traP LT#3 でのスライドです
http://ark4rk.hatenablog.com/entry/2018/01/18/040938
Ark
January 17, 2018
Other Decks in Programming
See All in Programming
HTML-in-Canvasで作る未来のWeb UI表現
clockmaker
5
5.1k
外から家のPCの電源入れたい!をPHPで解決する
kawashimo0
1
130
Long Living Tokens, Die, Die, Die! (or: The One Ring is Banned in Modern)
sylph01
0
300
Augmenting AI with the Power of Jakarta EE
ivargrimstad
0
180
Workers Cache を知る
syumai
0
360
Atomic Design, Enforced: Scaling Mobile Design Systems (next.app devCon / droidCon Berlin 2026)
steliosf
PRO
0
170
GemmaをJevのように使ってみる / Use Gemma like Jev
kishida
5
790
なぜCTOを降りてFDEを選んだのか?〜なぜプロダクト企業がFDEで顧客の現場に踏み込むのか〜
gonta
1
210
Next.js: The final boss of Web Performance
guaca
0
250
AI時代のコードレビューは人に向けるな、仕組みに向けろ
texmeijin
5
3.7k
Web Framework Benchmark Battle 2026, Any%
a_matsuda
2
2k
Everything will be SERVERLESS — 信じて運用した10年の経験値 / Everything Will be Serverless — Lessons Learned from 10 Years of Operational Experience
seike460
PRO
1
1.1k
Featured
See All Featured
Embracing the Ebb and Flow
colly
88
5.2k
Collaborative Software Design: How to facilitate domain modelling decisions
baasie
1
340
Balancing Empowerment & Direction
lara
6
1.3k
How STYLIGHT went responsive
nonsquared
100
6.3k
Information Architects: The Missing Link in Design Systems
soysaucechin
1
1.2k
Rails Girls Zürich Keynote
gr2m
96
14k
Typedesign – Prime Four
hannesfritz
42
3.2k
Evolution of real-time – Irina Nazarova, EuRuKo, 2024
irinanazarova
9
1.6k
[Rails World 2026] Durable orchestration on Rails: from continuation to workflow
palkan
1
750
Context Engineering - Making Every Token Count
addyosmani
9
1.2k
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
31
2.9k
Helping Users Find Their Own Way: Creating Modern Search Experiences
danielanewman
31
3.4k
Transcript
ゲーム制作に活かす 座標系の話 注) 3Dの話はしません Tokyotech traP LT#3 2018 1/17(Wed)
自己紹介 発表者: Ark Twitter: @arkark_ ゲーム作ったりしてます 競プロとか
突然ですが
どう実装しますか? 二次元平面上で次の2つの図形がある。 図形A: 点(x , y )とのマンハッタン距離がr 以下の領域 図形B: 点(x
, y )とのマンハッタン距離がr 以下の領域 AとBが衝突しているかを判定するには? A A A B B B
マンハッタン距離: d((x , y ), (x , y )) :=
∣x − x ∣ + ∣y − y ∣ (1, 1)と(4, 3)のマンハッタン距離は ∣1 − 4∣ + ∣1 − 3∣ = 3 + 2 = 5 1 1 2 2 1 2 1 2
赤: (x , y ) = (0, 1)、r = 3
緑: (x , y ) = (3, 2)、r = 2 A A A B B B
斜めに傾いた正方形同士の判定 斜めのまま処理するのは大変そう
45度回転してみる
これなら簡単に判定できそう
45度回転の仕方 回転の回転行列で座標を変換する 4 π ( X Y ) = ⎝
⎛cos 4 π sin 4 π − sin 4 π cos 4 π ⎠ ⎞ ( x y ) = √2 1 ( x − y x + y )
45度回転の仕方 判定にはスケーリングは関係しない は無視して良い √2 1 ( X Y ) =
( x − y x + y )
この方法で回転するとこうなる あとは、x軸、y軸それぞれに関して判定すれば良い
つまり 座標系を変える ⇒ 見える世界が変わる ⇒ 実装しやすくなる(かも) ⇒ コードが単純になる(かも)
余談 実は回転後の図形は (x, y)からのチェビシェフ距離がr以下であるよ うな点の集合からなる図形 チェビシェフ距離: max{∣x − x ∣
+ ∣y − y ∣} これは競プロでたまに出るテク 「マンハッタン距離が出たら45度回転させてチ ェビシェフ距離で考える」 1 2 1 2
その他の例 平行移動で原点を画面の中心にする ⇒ 極座標に変換する { r θ = √x +
y 2 2 = atan2(y, x)
ところで
Hexcellsというゲームを知っ ていますか
Hexcells
正六角形のセルが 規則正しく並んでいる
どうやって実装しよう?
座標変換すると楽できる?
Hexagonal Coordinates
いい感じに線形変換をす るとできる ⎩ ⎪ ⎪ ⎪ ⎨ ⎪ ⎪ ⎪
⎧ ( q r ) s = size 1 ⎝ ⎜ ⎛ 3 2 − 3 1 0 3 √3 ⎠ ⎟ ⎞ ( x y ) = −q − r
逆変換: = size 距離関数: ( x y ) ⎝ ⎜
⎛ 2 3 2 √3 0 √3⎠ ⎟ ⎞ ( q r ) d , = ⎝ ⎛ ⎝ ⎛q1 r1 s1 ⎠ ⎞ ⎝ ⎛q2 r2 s2 ⎠ ⎞ ⎠ ⎞ ∣q − q ∣ + ∣r − r ∣ + ∣s − s ∣ 1 2 1 2 1 2
デモ
まとめ 実装が難しそうなら 座標系を変えてみると有効な場合がある 例: 回転 (E.g. マンハッタン → チェビシェフ) 平行移動
極座標 Hexagonal Coordinates 詳しく知りたい人向け→ Hexagonal Grids