1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

n番煎じの2次元空間の線分同士の交差判定をcolabで実装してみる

Last updated at Posted at 2019-08-18

調べればいくらでも出てくる外積を用いた線分同士の衝突判定
Google Colaboratoryで組んでおきました.
ここからサンプルが動きます.直線abとcdの衝突判定をします.
数学的な説明は他のところに任せます.

\begin{bmatrix}
temp1
\end{bmatrix}
=
\begin{bmatrix}
bx-ax\\
by-ay
\end{bmatrix}
\times
\begin{bmatrix}
cx-ax\\
cy-ay
\end{bmatrix}
\\
\begin{bmatrix}
temp2
\end{bmatrix}
=
\begin{bmatrix}
bx-ax\\
by-ay
\end{bmatrix}
\times
\begin{bmatrix}
dx-ax\\
dy-ay
\end{bmatrix}
\\
\begin{bmatrix}
temp3
\end{bmatrix}
=
\begin{bmatrix}
dx-cx\\
dy-cy
\end{bmatrix}
\times
\begin{bmatrix}
ax-cx\\
ay-cy
\end{bmatrix}
\\
\begin{bmatrix}
temp4
\end{bmatrix}
=
\begin{bmatrix}
dx-cx\\
dy-cy
\end{bmatrix}
\times
\begin{bmatrix}
bx-cx\\
by-cy
\end{bmatrix}
\\
\begin{cases}
(temp1\bullet temp2 \leq 0) \cap(temp3\bullet temp4 \leq 0) & collision  
\\
otherwise & no collision
\end{cases}

修正(2019/09/04)

temp1とtemp2の部分しか考えていませんでしたが,それでは不十分だったので修正しました.

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?