本文介绍了Three.js-来自Math.Plane的PlaneGeometry的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图通过Three.js中的一组点绘制最小二乘平面.我有一个飞机定义如下:

I am trying to draw a least squares plane through a set of points in Three.js. I have a plane defined as follows:

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

我的理解是,我需要采取该平面并将其用于绘制几何图形,以便创建一个网格以添加到场景中以进行显示:

My understanding is that I need to take that plane and use it to come up with a Geometry in order to create a mesh to add to the scene for display:

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

我一直在尝试使用以获取几何图形.这是我想出的:

I've been trying to apply this answer to get the geometry. This is what I came up with:

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();

但是飞机根本不显示,也没有错误表明我可能在哪里出了问题.

But the plane is not displayed at all, and there are no errors to indicate where I may have gone wrong.

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

So my question is, how can I take my Math.Plane object and use that as a geometry for a mesh?

推荐答案

此方法应创建平面的网格可视化.我不确定这对最小二乘拟合的适用性.

This approach should create a mesh visualization of the plane. I'm not sure how applicable this would be towards the least-squares fitting however.

 // 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);

这篇关于Three.js-来自Math.Plane的PlaneGeometry的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-18 14:05