javascript - How to calculate angle between two planes? -


i have 2 planes, how can calculate angle between them? possible calculate angle between 2 object3d points in case of planes?

heres example fiddle: https://jsfiddle.net/rsu842v8/1/

  const scene = new three.scene();    const camera = new three.perspectivecamera(45, window.innerwidth / window.innerheight, 1, 1000);    camera.position.set(25, 25, 12);      var material = new three.meshbasicmaterial({      color: 0x00fff0,      side: three.doubleside    });    window.plane1 = new three.mesh(new three.planegeometry(10, 10), material);    scene.add(plane1);      plane1.position.set(0.3, 1, -2);    plane1.rotation.set(math.pi / 3, math.pi / 2, 1);      window.plane2 = new three.mesh(new three.planegeometry(10, 10), new three.meshbasicmaterial({      color: 0x0fff00,      side: three.doubleside    }));    scene.add(plane2);        // setup rest    var pointlight = new three.pointlight(0xffffff);    pointlight.position.x = 10;    pointlight.position.y = 50;    pointlight.position.z = 130;    scene.add(pointlight)      const renderer = new three.webglrenderer({      antialias: true    });    renderer.setsize(window.innerwidth, window.innerheight);    renderer.setclearcolor(0x20252f);    renderer.setpixelratio(window.devicepixelratio);    document.body.appendchild(renderer.domelement);      const controls = new three.orbitcontrols(camera, renderer.domelement);      animate();      // todo: angle between plane1 , plane2?      function animate() {      requestanimationframe(animate);      render();    }      function render() {      renderer.render(scene, camera);    }
<script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/r82/three.js"></script>  <script src="https://yume.human-interactive.org/examples/buffer-geometry/orbitcontrols.js"></script>

you want find angle between 2 three.js plane meshes.

unrotated, three.planegeometry oriented face positive z-axis. plane's normal points in direction of positive z-axis.

so, create ( 0, 0, 1 ) vector, , apply same rotation applied plane mesh.

note plane.quaternion automatically updated when set plane.rotation, can use quaternion in calculation -- so:

var vec1 = new three.vector3( 0, 0, 1 ); // create once , reuse var vec2 = new three.vector3( 0, 0, 1 );  vec1.applyquaternion( plane1.quaternion ); vec2.applyquaternion( plane2.quaternion );  var angle = vec1.angleto( vec2 ); // radians 

the problem bit more complicated if planes children of other rotated objects.

of course, can use angleto() find angle between 2 vectors.

three.js r.86


Comments

Popular posts from this blog

html - How to set bootstrap input responsive width? -

javascript - Highchart x and y axes data from json -

javascript - Get js console.log as python variable in QWebView pyqt -