最も簡単な解決策は、あなたが探している可能性が最も高いと思いますが、軸に沿った境界ボックスを計算することです。これは、最小/最大の x と y の値を見つけてから、それらの。
ジオメトリが表現されているタイプを投稿していないことを考えると、そのための疑似コードを提供します...
type point { float x; float y; }
type box { point topleft; point topright; point bottomleft; point bottomright; }
function bounding_box(points)
{
xmin = min(points.x)
xmax = max(points.x)
ymin = min(points.y)
ymax = max(points.y)
return new box{
topleft = { x = xmin, y = ymax },
topright = { x = xmax, y = ymax },
bottomleft = { x = xmin, y = ymin },
bottomright = { x = xmax, y = ymin }
};
}
したがって、これらを考えると:
point[] points = [[x = -2, y = 0], [x = 1, y = 2], [x = 1, y = 1], [x = -1, y = -2]];
box bounds = bounding_box(points);
次のすべてが true になります。
bounds.topleft == [x = -2, y = 2];
bounds.topright == [x = 1, y = 2];
bounds.bottomleft == [x = -2, y = -2];
bounds.bottomright == [x = -1, y = -2];
もちろん、座標系の座標が一番上にある場合 (たとえば、典型的なディスプレイのように)、計算を逆にする必要があります。または、最初にオブジェクト空間で結果を計算してから、後で論理空間に変換します。
将来、任意に配置されたボックスに更新することを決定した場合に備えて、四隅すべてを表すボックスのタイプを選択したことに注意してください (ただし、同じトークンで、点 + 2 つのベクトルを使用することもできます)。それ)。