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

更新

[[公開メモ]]

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

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

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

* Mathematica で確かめる [#y6b0a391]

正確な距離関数はこう:

&math(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]

&attachref;

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

&math(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]

&attachref;

Counter: 14852 (from 2010/06/03), today: 6, yesterday: 9