[英]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.