Skip to content

Instantly share code, notes, and snippets.

@tondol
Last active December 17, 2015 04:58
Show Gist options
  • Save tondol/5553976 to your computer and use it in GitHub Desktop.
Save tondol/5553976 to your computer and use it in GitHub Desktop.
点と平面の距離
平面 := ax + by + cz + d = 0
点P := (x0, y0, z0)
点Q := (x1, y1, z1) = 点Pから平面に下ろした垂線が平面と交差する点
平面の法線ベクトル := (a, b, c)
l := 点Pと平面の距離
ベクトルPQは法線ベクトルと平行だから: (x1, y1, z1) - (x0, y0, z0) = t・(a, b, c) …… [1]
点Qは平面上の点だから: ax1 + by1 + cz1 + d = (a, b, c)・(x1, y1, z1) + d = 0 …… [2]
[1]より
(x1, y1, z1) = (x0, y0, z0) + t・(a, b, c) …… [3]
[2], [3]より
(a, b, c)・((x0, y0, z0) + t・(a, b, c)) + d = 0
(a, b, c)・(x0, y0, z0) + t・(a^2 + b^2 + c^2) + d = 0
t = (- d - (x0, y0, z0)・(a, b, c)) / (a^2 + b^2 + c^2)
t = - (ax0 + by0 + cz0 + d) / (a^2 + b^2 + c^2) …… [4]
lは点Pと平面の距離 = ベクトルPQの大きさだから、[1]より
l = |(x1, y1, y2) - (x0, y0, z0)|=|t・(a, b, c)|
ここで、[4]よりtを代入すれば
l = |(- (ax0 + by0 + cz0 + d) / (a^2 + b^2 + c^2))(a, b, c)|
l = |(ax0 + by0 + cz0 + d) / (a^2 + b^2 + c^2)||sqrt(a^2 + b^2 + c^2)|
l = |(ax0 + by0 + cz0 + d) / sqrt(a^2 + b^2 + c^2)|
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment