這是一個更通用的數學/代碼問題,在我的情況下,我需要它用于 Godot / GDScript。我有一個虛擬立方體定義為具有厚度偏移的原點,我回圈遍歷每個軸上的最小值和最大值以執行每個單元的動作。因此,普通立方體表示為:
const org = Vector3(32, 48, 64)
const thick = 16
const mins = Vector3(org.x - thick, org.y - thick, org.z - thick)
const maxs = Vector3(org.x thick, org.y thick, org.z thick)
for x in range(mins.x, maxs.x, thick):
for y in range(mins.y, maxs.y, thick):
for z in range(mins.z, maxs.z, thick):
var vec = Vector3(x, y, z)
發生的事情是我想將此立方體細分為 8 個彼此完美接觸的立方體。我需要一個mins_0/ maxs_0, mins_1/ maxs_1, ... , mins_7/maxs_7每個代表立方體的一部分。
我被困在數學上:我不知道如何轉置原點和厚度偏移,顯然保持順序,以便任何回圈都從正確的位置開始(mins.# < maxs.#總是)。我只知道兩種顯而易見的組合:
mins_0 = Vector3(org.x - thick, org.y - thick, org.z - thick)
maxs_0 = Vector3(org.x, org.y, org.z)
mins_4 = Vector3(org.x, org.y, org.z)
maxs_4 = Vector3(org.x thick, org.y thick, org.z thick)
如何以正確的順序填充其他 6 個空間以覆寫剩余區域?
uj5u.com熱心網友回復:
這使用矢量算術會簡單得多,但我們可以使用原始坐標來做到這一點:
mins_0 = Vector3(org.x - thick, org.y - thick, org.z - thick)
maxs_0 = Vector3(org.x, org.y, org.z)
mins_1 = Vector3(org.x - thick, org.y - thick, org.z)
maxs_1 = Vector3(org.x, org.y, org.z thick)
mins_2 = Vector3(org.x - thick, org.y, org.z - thick)
maxs_2 = Vector3(org.x, org.y thick, org.z)
mins_3 = Vector3(org.x - thick, org.y, org.z)
maxs_3 = Vector3(org.x, org.y thick, org.z thick)
mins_4 = Vector3(org.x, org.y - thick, org.z - thick)
maxs_4 = Vector3(org.x thick, org.y, org.z)
mins_5 = Vector3(org.x, org.y - thick, org.z)
maxs_5 = Vector3(org.x thick, org.y, org.z thick)
mins_6 = Vector3(org.x, org.y, org.z - thick)
maxs_6 = Vector3(org.x thick, org.y thick, org.z)
mins_7 = Vector3(org.x, org.y, org.z)
maxs_7 = Vector3(org.x thick, org.y thick, org.z thick)
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/412186.html
標籤:
上一篇:計算特征向量時沒有得到預期的輸出
下一篇:獲取數字的所有整數磁區
