In my project, I am working with an array of Vector3 that represents a path to be drawn.
For each consecutive point in the path, I need to determine the direction it will take - either straight, left, or right if the angle is steep enough.
Approach taken so far
I attempted to create an Object3D for every vector in the array and then aligning it (using lookAt) towards the next vector. However, I encountered an issue where the rotation of the temporary object became NaN.
To address this problem, I set up two Object3D instances to retrieve the world position of the second object.
Expected outcome My goal is to calculate and store the angle, in radians or degrees, of each Object3D to determine its corresponding direction.
const path = [
{ "x": -2.47, "y": 0, "z": 7.61 },
{ "x": -2.14, "y": 0, "z": 6.63 },
{ "x": -1.09, "y": 0, "z": 2.33 },
{ "x": -1.06, "y": 0, "z": 0.8 },
{ "x": -1.83, "y": 0, "z": 0.71 },
{ "x": -9.12, "y": 0, "z": 0.39 },
{ "x": -9.48, "y": 0, "z": -0.66 }
];
if (path.length > 2) {
let index = 0;
const pathSegments = Math.floor(path.length / 2);
for (let i = 0; i<pathSegments; i++) {
const v1 = path[index];
const v2 = path[index+1];
// Create temporary object
const tempObject = new THREE.Object3D();
tempObject.position.set(v1);
tempObject.lookAt(v2);
console.log(tempObject.rotation);
}
}
I suspect there may be a more efficient way to approach this task. Any guidance or suggestions would be highly appreciated!