 # Rotating plane around line

I have a plane and two points on scene that are connected. And my question is how can I rotate the plane around the line?

Like so, but this is hardcoded. Is there a way to do it dynamically

Have you tried Object3D.rotateOnAxis ?

Since your segment does not go through the origin, you can do this :

``````// vecA == Vector3 start of your segment
// vecB == Vector3 end of your segment
const vec = new THREE.Vector3();

vec.copy( vecA ).sub( vecB );
mesh.position.sub( vecA );
mesh.rotateOnAxis( vec, angle );
``````

Also consider using Object3D.rotateOnWorldAxis for world space rotation.

1 Like
``````		var planeGeom = new THREE.PlaneGeometry(100, 100);
var plane = new THREE.Mesh(planeGeom, new THREE.MeshBasicMaterial({
color: "lightgray",
transparent: true,
opacity: 0.5,
side: THREE.DoubleSide
}));

let vecA = new THREE.Vector3(50, 20, 0);
let vecB = new THREE.Vector3(-50, 20, 0);
const vec = new THREE.Vector3();

vec.copy(vecA).sub(vecB);
plane.position.sub(vecA);
plane.rotateOnAxis(vec, Math.PI / 5);