How do you rotate a Group of Objects around an arbitrary axis?


I have tried to use rotGroup.rotateOnAxis(rotGroup position.normalize(), Math.PI/2 for ex.) but what I understand is this rotates the rotGroup around the line from the origin to the rotGroup position. Instead I want to rotate rotGroup around a vertical line through its position.

Thank you for all of your help!

Could you add an explanatory picture with the desired result?

i had this same issue a week ago, My 3D model is not rotating around its origin , use the applyMatrix.
myGroup.applyMatrix( new THREE.Matrix4().makeTranslation(x, y, z) );

how it works is that you can give the 3d model a new point to rotate around, so i found an origin point and passed it as a matrix, you can do the same for your vertical line

It’s not valid to pass a position vector as the first argument to Object3D.rotateOnAxis. Instead, it’s a normalized vector which defines the axis.

Can you clarify what I pass in as (x,y,z)?

Oh, ok. I fixed that. Thank you.

I want what would happen with rotGroup.rotateY(Math.PI/2) if the group was at the origin but when it is not at the origin.

Follow @Mugen87 's advice of using .rotateOnAxis() then.
By the way, could you provide a live code example of your approach?

I tried, but I don’t have the same issues in my simplified example.

Thank you so much for all of your help!
I had a hierarchy of 3 Groups with the final group with 4 Meshes. The way I got it to work was to use the positions of the 4 Meshes to transfer the positions to the Groups so that the Group position is the center of the Group using

myGroup.applyMatrix( new THREE.Matrix4().makeTranslation(x, y, z) );

Now that each Group’s position is its center, I can simply use rotateX(), rotateY(), and rotateZ() to rotate each Group on its own x,y, and z axes.

System has system_3objects (Group) - Position Before: (0,0,0) After: Center of Mass
Strand has system_3objects.children[x] (Group) - Position Before: (0,0,0) After: Center of Mass
Nucleotide has system_3objects.children[x].children[x] (Group) - Position Before: (0,0,0) After: Center of Mass
4 Meshes

function updatePos(sys_count) {
    for (let h = sys_count; h < sys_count + 1; h++) { // 1 System at a time
        let cmssys = new THREE.Vector3(); // System center of mass (cm)
        let n = systems[h].system_length(); // # of Nucleotide Groups in System
        for (let i = 0; i < systems[h].system_3objects.children.length; i++) { // 1 Strand at a time
            let n1 = systems[h].system_3objects.children[i].children.length; // # of Nucleotide Groups in Strand
            let cms = new THREE.Vector3(); // Strand cm
            for (let j = 0; j < n1; j++) { // 1 Nucleotide at a time
                let rotobj = systems[h].system_3objects.children[i].children[j]; // a Nucleotide Group
                let n2 = rotobj.children.length; // # of Meshes in Nucleotide Group
                let cms1 = new THREE.Vector3(), currentpos = new THREE.Vector3(); // Nucleotide cm
                cms.add(rotobj.children[3].position); // 3rd Mesh is at cm of Nucleotide Group
                cms1 = rotobj.children[3].position;
                let cmsx = cms1.x, cmsy = cms1.y, cmsz = cms1.z;

            for (let k = 0; k < n2; k++) {
                rotobj.children[k].applyMatrix(new THREE.Matrix4().makeTranslation(-cmsx, -cmsy, -cmsz)); // Move each Mesh by cm
            rotobj.applyMatrix(new THREE.Matrix4().makeTranslation(cmsx, cmsy, cmsz)); // Move Nucleotide Group by cm
        let mul = 1.0 / n1;
        cms.multiplyScalar(mul); // Calc cm
        for (let k = 0; k < n1; k++) {
            systems[h].strands[i].strand_3objects.children[k].applyMatrix(new THREE.Matrix4().makeTranslation(-cms.x, -cms.y, -cms.z)); // Move each Nucleotide Groups by cm
        systems[h].strands[i].strand_3objects.applyMatrix(new THREE.Matrix4().makeTranslation(cms.x, cms.y, cms.z)); // Move Strand by cm
    let mul = 1.0 / n;
    cmssys.multiplyScalar(mul); // Calc cm
    for (let k = 0; k < systems[h].system_3objects.children.length; k++) {
        systems[h].system_3objects.children[k].applyMatrix(new THREE.Matrix4().makeTranslation(-cmssys.x, -cmssys.y, -cmssys.z)); // Move each Strand by cm
    systems[h].system_3objects.applyMatrix(new THREE.Matrix4().makeTranslation(cmssys.x, cmssys.y, cmssys.z)); // Move System by cm


1 Like

told you so, the

does the trick