使用three.js如何计算旋转度数和旋转到方向向量后的点数?
How to calculate the points after rotate degrees and rotate to direction vector by using three.js?
如何通过three.js计算旋转度数旋转到方向向量(-42,51,11)后的点A到H?
提前谢谢你,请原谅我的英语不好。最好的问候。
const tree = [
[ 0, 0, 0], // A
[ 2, 151, 2], // B
[ -62, 283, 63], // C
[ 62, 296, -58], // D
[-104, 334, 74], // E
[ -58, 338, 45], // F
[ 67, 403, -55], // G
[ 105, 365, -86], // H
]
此代码将围绕定义为顶点 [-42, 51, 11]
的轴对树中的所有向量应用 90 度旋转。所以旋转轴定义为从[0,0,0]
到[-42, 51, 11]
的一条线,因此点A
在旋转时不会改变。
const tree = [
[ 0, 0, 0], // A
[ 2, 151, 2], // B
[ -62, 283, 63], // C
[ 62, 296, -58], // D
[-104, 334, 74], // E
[ -58, 338, 45], // F
[ 67, 403, -55], // G
[ 105, 365, -86], // H
]
// Define the rotation axis:
let axis = new THREE.Vector3(-42, 51, 11)
// Normalize the axis:
axis.normalize()
// Define the matrix:
let matrix = new THREE.Matrix4()
// Define the rotation in radians:
let radians = 90 * Math.PI / 180
// Rotate the matrix:
matrix.makeRotationAxis(axis, radians)
// Now apply the rotation to all vectors in the tree
let newTree = []
for(const vector of tree) {
// Define the vector3:
let vec = new THREE.Vector3(vector[0], vector[1], vector[2])
vec.applyMatrix4(matrix)
newTree.push(vec.toArray()) // toArray is optional, you may want to keep the original Vector3 object
}
// newTree now holds the rotated vectors
console.log(newTree)
如何通过three.js计算旋转度数旋转到方向向量(-42,51,11)后的点A到H?
提前谢谢你,请原谅我的英语不好。最好的问候。
const tree = [
[ 0, 0, 0], // A
[ 2, 151, 2], // B
[ -62, 283, 63], // C
[ 62, 296, -58], // D
[-104, 334, 74], // E
[ -58, 338, 45], // F
[ 67, 403, -55], // G
[ 105, 365, -86], // H
]
此代码将围绕定义为顶点 [-42, 51, 11]
的轴对树中的所有向量应用 90 度旋转。所以旋转轴定义为从[0,0,0]
到[-42, 51, 11]
的一条线,因此点A
在旋转时不会改变。
const tree = [
[ 0, 0, 0], // A
[ 2, 151, 2], // B
[ -62, 283, 63], // C
[ 62, 296, -58], // D
[-104, 334, 74], // E
[ -58, 338, 45], // F
[ 67, 403, -55], // G
[ 105, 365, -86], // H
]
// Define the rotation axis:
let axis = new THREE.Vector3(-42, 51, 11)
// Normalize the axis:
axis.normalize()
// Define the matrix:
let matrix = new THREE.Matrix4()
// Define the rotation in radians:
let radians = 90 * Math.PI / 180
// Rotate the matrix:
matrix.makeRotationAxis(axis, radians)
// Now apply the rotation to all vectors in the tree
let newTree = []
for(const vector of tree) {
// Define the vector3:
let vec = new THREE.Vector3(vector[0], vector[1], vector[2])
vec.applyMatrix4(matrix)
newTree.push(vec.toArray()) // toArray is optional, you may want to keep the original Vector3 object
}
// newTree now holds the rotated vectors
console.log(newTree)