平方根を使わずに距離を求める のバックアップ(No.1)

更新


公開メモ

平面状の2点間の距離を平方根を使わずに計算する

http://d.hatena.ne.jp/nowokay/20120604

twitter にてこちらの記事を知り、少し調べてみました。

Mathematica で確かめる

正確な距離関数はこう:

d_\mathrm{sqrt}=\sqrt{x^2+y^2}

LANG:Mathematica
distance[x_, y_] := Sqrt[x^2 + y^2]
Plot3D[distance[x, y], {x, -1, 1}, {y, -1, 1}, ImageSize -> Large]

[添付]

最大値、最小値を利用した近似はこう (a=1007/1024, b=441/1024)

d_\mathrm{max,min}=a\mathrm{max}(|x|,|y|)+b\mathrm{min}(|x|,|y|)

LANG:Mathematica
distance2[x_, y_, a_, b_] := a Max[Abs[x], Abs[y]] + b Min[Abs[x], Abs[y]]
Plot3D[distance2[x, y, 1007/1024, 441/1024], {x, -1, 1}, {y, -1, 1}, ImageSize -> Large]

[添付]


Counter: 14711 (from 2010/06/03), today: 3, yesterday: 0