![](/img/trans.png)
[英]how re-scale a range of ratio values, to start from 1 rather then 0, without losing statics significance
[英]How to re-scale vertices to fit within certain range while preserving aspect ratio?
我正在嘗試標准化網格的頂點以適應范圍從 -0.5 到 +0.5 的邊界框。 使用以下邏輯,我已經完成了:
# Calculate max and min values for each axis to
# get existing bounding box
x_max = np.max(vertices[:, 0])
y_max = np.max(vertices[:, 1])
z_max = np.max(vertices[:, 2])
x_min = np.min(vertices[:, 0])
y_min = np.min(vertices[:, 1])
z_min = np.min(vertices[:, 2])
# Calculate normalized vertices
normalized_x = 1 * (vertices[:, 0] - x_min) / (x_max - x_min) - 0.5
normalized_y = 1 * (vertices[:, 1] - y_min) / (y_max - y_min) - 0.5
normalized_z = 1 * (vertices[:, 2] - z_min) / (z_max - z_min) - 0.5
normalized_vertices = np.column_stack((normalized_x, normalized_y, normalized_z))
然而,我的問題是,雖然我的網格頂點現在在適當的范圍內,但縱橫比沒有保留(所以更長的維度被完全壓扁了)。 我將如何正確縮放,以便我的點仍然在 -0.5 到 +0.5 的最大值范圍內,但保留原始縱橫比?
使用最大值:
(x_max - x_min)
(y_max - y_min)
(z_max - z_min)
並除以這個值,假設它是max_value :
normalized_x = 1 * (vertices[:, 0] - x_min) / max_value - 0.5
normalized_y = 1 * (vertices[:, 1] - y_min) / max_value - 0.5
normalized_z = 1 * (vertices[:, 2] - z_min) / max_value - 0.5
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.