Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/three.js/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/370.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Graphics 如何用已知的两个对角位置向量在三个J中绘制平面?_Graphics_Three.js - Fatal编程技术网

Graphics 如何用已知的两个对角位置向量在三个J中绘制平面?

Graphics 如何用已知的两个对角位置向量在三个J中绘制平面?,graphics,three.js,Graphics,Three.js,我们可以使用此代码在任意位置添加平面几何体: var geometry = new THREE.PlaneGeometry( 5, 20, 32 ); var material = new THREE.MeshBasicMaterial( {color: 0xffff00, side: THREE.DoubleSide} ); var plane = new THREE.Mesh( geometry, material ); scene.add( plane ); 但当两个对角线位置已知时,我

我们可以使用此代码在任意位置添加平面几何体:

var geometry = new THREE.PlaneGeometry( 5, 20, 32 );
var material = new THREE.MeshBasicMaterial( {color: 0xffff00, side: THREE.DoubleSide} );
var plane = new THREE.Mesh( geometry, material );
scene.add( plane );
但当两个对角线位置已知时,我们如何添加平面呢。这可能吗

到目前为止,最接近这一点的是得到两个位置的中心,它正确地定位了平面,但大小不正确:

var dir = pointB.clone().subtract(pointA);
var length = dir.length();
dir = dir.normalize().scale(length * 50);
center_position = pointA.clone().add(dir);

方向在我的例子中并不重要,可以通过lookat()设置。

找到这两个方向的减法向量,其绝对值是平面大小。 这两个的平均向量是平面的中心

示例(r120):

正文{
溢出:隐藏;
保证金:0;
}

从“导入*为三”https://threejs.org/build/three.module.js";
从导入{OrbitControls}”https://threejs.org/examples/jsm/controls/OrbitControls.js";
让场景=新的三个。场景();
让摄像头=新的三个透视摄像头(60,内宽/内高,1100);
摄像机位置设置(0,5,10);
让renderer=new THREE.WebGLRenderer();
设置大小(innerWidth,innerHeight);
document.body.appendChild(renderer.doElement);
let controls=新的轨道控件(摄影机、渲染器.doElement);
scene.add(新的THREE.GridHelper());
设vec1=new-THREE.Vector3(0,2,0);
设vec2=new-THREE.Vector3(4,0,0);
设size=new-THREE.Vector3()子向量(vec2,vec1);
设center=new THREE.Vector3().addVectors(vec1,vec2).multiplyScalar(0.5);
设planeWidth=Math.abs(size.x);
设平面高度=数学绝对值(尺寸y);
设planeGeom=新的三个PlaneBufferGeometry(planeWidth、planeHeight、planeWidth、planeHeight);
让planeMat=new THREE.MeshBasicMaterial({颜色:“aqua”,线框:true});
设平面=新的三网格(planeGeom、planeMat);
平面、位置、复印件(中心);
场景。添加(平面);
renderer.setAnimationLoop(()=>{
渲染器。渲染(场景、摄影机);
});

让PlaneWidth=Math.abs(size.z);如果(planeWidth
添加了此代码,此修改方向正确吗?。