三次元以上を対象.
とりあえず valarray で書いてみた.幾何計算はおきまりの operator ほげほげを書かないといけないので,三次元であっても valarray が良いような気がする.
#include <valarray> typedef double number; typedef valarray<number> point; const int dim = 3; number dot(const point& a, const point& b) { return (a * b).sum(); } point cross(const point& a, const point& b) { return a.cshift(+1)*b.cshift(-1) - a.cshift(-1)*b.cshift(+1); } number dist2(const point& a, const point& b) { return dot(a-b, a-b); }
Last Modified: 2006.12.11 08:46:33.