5
7

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.

2点を交わる直線2組が交わる交点

Posted at

$(x_1,y_1)$と$(x_2,y_2)$、$(x_3,y_3)$と$(x_4,y_4)$それぞれを通る直線を求め、それら2つの直線が交わる交点を求める。

点と直線の公式によると、$(x_1,y_1)$と$(x_2,y_2)$を通る直線は

\begin{eqnarray}
y-y_{1}&=&\frac{y_{2}-y_{1}}{x_{2}-x_{1}}\left(x-x_{1}\right)\\
y & =&\frac{y_{2}-y_{1}}{x_{2}-x_{1}}\left(x-x_{1}\right)+y_{1}\\
  &=&\frac{y_{2}-y_{1}}{x_{2}-x_{1}}x+\left(y_{1}-\frac{y_{2}-y_{1}}{x_{2}-x_{1}}x_{1}\right)
\end{eqnarray}

同様に、$(x_3,y_3)$と$(x_4,y_4)$を通る直線は

\begin{eqnarray}
y=\frac{y_{4}-y_{3}}{x_{4}-x_{3}}x+\left(y_{3}-\frac{y_{4}-y_{3}}{x_{4}-x_{3}}x_{3}\right)
\end{eqnarray}

同様に2本の直線$y=ax+b$と$y=cx+d$は$a\neq c$のとき交点を一つ持つ。その座標は、連立方程式を求めると、
$x$に関しては

\begin{eqnarray}
ax+b&=&cx+d\\
\left(a-c\right)x&=&d-b\\
x&=&\frac{d-b}{a-c}
\end{eqnarray}

$y$に関しては

\begin{eqnarray}
y	&=&	a\frac{d-b}{a-c}+b\\
	&=&	\frac{a\left(d-b\right)+b\left(a-c\right)}{a-c}\\
	&=&	\frac{ad-ab+ab-bc}{a-c}\\
	&=&	\frac{ad-bc}{a-c}\\
 
\end{eqnarray}

従って、

\left(\frac{d-b}{a-c},\frac{ad-bc}{a-c}\right)

である。

例として、

\begin{eqnarray}
(x_1,y_1)&=&(4,11),\\
(x_2,y_2)&=&(2,7),\\
(x_3,y_3)&=&(3,11),\\
(x_4,y_4)&=&(1,1).
\end{eqnarray}

とし、以下のスクリプトにより交点を求める。

from numpy import *
p1 = array([4, 11])
p2 = array([2, 7])

p3 = array([3, 11])
p4 = array([1, 1])

def getIntersection(p1, p2, p3, p4):
    a = (p2[1] - p1[1]) / (p2[0] - p1[0])
    b = p1[1] - a * p1[0] 
    
    c = (p4[1] - p3[1]) / (p4[0] - p3[0])
    d = p3[1] - c * p3[0] 
    
    print("a={:.2f}, b={:.2f}, c={:.2f}, d={:.2f}".format(a, b, c, d))

    return (d-b)/(a-c), (a*d-b*c)/(a-c)

print("intersec. point is ({:.4f},{:.4f})".format(*getIntersection(p1,p2,p3,p4)))

結果:

a=2.00, b=3.00, c=5.00, d=-4.00
intersec. point is (2.3333,7.6667)

となり、$y=2x+3$と$y=5x-4$の交点は$(2.3333,7.6667)$であることが分かる。

5
7
1

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
5
7

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?