Translate position with rotation

Hello :slight_smile:
I have a cylinder mesh in my scene. I first lower its “center/pivot” to its “feet” (so thats where its position is), and then rotate it by some value. After that I need to get the position of the other end of the cylinder. How would that be possible? Here is my code sample

let height = 10;
let cylGeo = new THREE.CylinderBufferGeometry( 2, 2, height );
let cyl = new THREE.Mesh( cylGeo, cylMat );
cyl.geometry.translate( 0 , height/2.0 , 0 );
cyl.position.copy( somePos );
let randRotation = Math.random()*2.0 - 1/0;
cyl.rotation.z += randRotation;
cyl.rotation.x += randRotation/2.0;
let otherEndPosition = ???

image

Before cyl has any rotations paplied, its blue end is at (0, height, 0). You can declare this position as a vector, apply the rotation quaternion to the vector, then read the end result.

Apply these lines after the end of your code, and you should get the answer:

let endVector = new THREE.Vector3(0, height, 0);
endVector.applyQuaternion(cyl.quaternion);

console.log(endVector.x + " : " + endVector.y + " : " + endVector.z);

You can read more about .applyQuaternion() in the Vector3 docs

Thank you for your quick response. I’ve tried your idea but it seems to scatter objects randomly around. Sorry for not mentioning it earlier, not sure if it’s important, but Im working on a procedural tree generator and thats why I need to know where each cylinder ends. Here is a jsfiddle
https://jsfiddle.net/tn59kdvg/2/

You’re going to need to console.log() the vector one step at a time, and see where it’s going wrong. I’ll bet it’s because you have to add a translation vector after you rotate it.