x
byの特定のボックスを取得y
して、 を設定x
して検索y
するか、その逆のいずれかで拡大しようとしています。この式は Python でどのように表現されますか (読みやすくするため)。内側のボックスが常に大きなボックス内に収まるように、このボックスを大きなボックスの内側に収めようとしています。
4322 次
3 に答える
6
new_y = (float(new_x) / x) * y
また
new_x = (float(new_y) / y) * x
于 2011-05-16T21:12:38.150 に答える
6
注: 私は実際には Python を使用していないため、これは疑似コードです。
必要なのは、2 つのボックスの相対的な縦横比です。これにより、新しい軸のどちらを新しいボックスと同じサイズにする必要があるかが決まります。
r_old = old_w / old_h
r_new = new_w / new_h
if (r_old > r_new) then
w = new_w // width of mapped rect
h = w / r_old // height of mapped rect
x = 0 // x-coord of mapped rect
y = (new_h - h) / 2 // y-coord of centered mapped rect
else
h = new_h
w = h * r_old
y = 0
x = (new_w - w) / 2
endif
于 2011-05-16T21:16:23.977 に答える
0
>>> import fractions
>>> x, y = 10, 10
>>> fix_rat = fractions.Fraction(x, y)
>>> fix_rat
Fraction(1, 1)
>>> x = 8
>>> if fractions.Fraction(x, y) != fix_rat:
y = x / fix_rat #well instead of y you should put the last one that has been changed
#but this is just an example
>>> y
Fraction(8, 1)
>>>
于 2011-05-16T21:14:49.727 に答える