gpt4 book ai didi

javascript - Three.js - 来自 Math.Plane 的 PlaneGeometry

转载 作者:太空宇宙 更新时间:2023-11-04 16:24:12 26 4
gpt4 key购买 nike

我正在尝试通过 Three.js 中的一组点绘制最小二乘平面。我有一个plane定义如下:

var plane = new THREE.Plane();
plane.setFromNormalAndCoplanarPoint(normal, point).normalize();

我的理解是,我需要使用该平面并使用它来得出几何图形,以便创建一个网格以添加到场景中进行显示:

var dispPlane = new THREE.Mesh(planeGeometry, planeMaterial);
scene.add(dispPlane);

我一直在尝试申请this answer得到几何图形。这就是我想到的:

plane.setFromNormalAndCoplanarPoint(dir, centroid).normalize();
planeGeometry.vertices.push(plane.normal);
planeGeometry.vertices.push(plane.orthoPoint(plane.normal));
planeGeometry.vertices.push(plane.orthoPoint(planeGeometry.vertices[1]));
planeGeometry.faces.push(new THREE.Face3(0, 1, 2));

planeGeometry.computeFaceNormals();
planeGeometry.computeVertexNormals();

但是飞机根本没有显示,也没有任何错误表明我可能出错的地方。

所以我的问题是,如何获取 Math.Plane 对象并将其用作网格的几何图形?

最佳答案

这种方法应该创建平面的网格可视化。不过,我不确定这对于最小二乘拟合有何适用性。

 // Create plane
var dir = new THREE.Vector3(0,1,0);
var centroid = new THREE.Vector3(0,200,0);
var plane = new THREE.Plane();
plane.setFromNormalAndCoplanarPoint(dir, centroid).normalize();

// Create a basic rectangle geometry
var planeGeometry = new THREE.PlaneGeometry(100, 100);

// Align the geometry to the plane
var coplanarPoint = plane.coplanarPoint();
var focalPoint = new THREE.Vector3().copy(coplanarPoint).add(plane.normal);
planeGeometry.lookAt(focalPoint);
planeGeometry.translate(coplanarPoint.x, coplanarPoint.y, coplanarPoint.z);

// Create mesh with the geometry
var planeMaterial = new THREE.MeshLambertMaterial({color: 0xffff00, side: THREE.DoubleSide});
var dispPlane = new THREE.Mesh(planeGeometry, planeMaterial);
scene.add(dispPlane);

关于javascript - Three.js - 来自 Math.Plane 的 PlaneGeometry,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40366339/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com