LoginSignup
0
0

アーカイブ:点から直線までの距離

Posted at
function prog(x1, y1, x2, y2, x3, y3)
    """
    (x1, y1) と (x2, y2) を通る直線に,(x3, y3) からおろした垂線の長さを求める
    戻り値は垂線の脚の座標と垂線の長さ(直線までの距離)
    """
    a = (y2 - y1)/(x2 - x1)
    x = (x3/a + y3 + a*x1 - y1)/(a + 1/a)
    y = a*(x - x1) + y1
    return (x, y, sqrt((x - x3)^2 + (y - y3)^2))
end
prog(1, 0, 15, 5, 0, 6)
(2.013574660633484, 0.36199095022624433, 5.986787866567181)
0
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
0
0