2016-11-01 20 views
1

Three.js内の点の集合を通して最小自乗平面を描こうとしています。私は次のように定義されたplaneを持っている:Three.js - Math.PlaneのPlaneGeometry

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オブジェクトをどのようにしてメッシュのジオメトリとして使用できるのですか?

+0

planeMaterialはどのように見えますか?あなたはplaneMaterial.sideを変更しようとしましたか?例えば、planeMaterial.side = THREE.DoubleSide – msun

+0

var planeMaterial = new THREE.MeshLambertMaterial({color:0xffff00、side:THREE.DoubleSide}); –

+0

私は頂点としてplane.normalを使用していることに気付きました:例えば、planeGeometry.vertices.push(plane.normal);それは有効ではないようです。代わりにplane.coplanarPoint()を使用すると運がいいですか? – msun

答えて

0

このアプローチでは、プレーンのメッシュ視覚化を作成する必要があります。しかし、これが最小2乗フィッティングにどのように適用可能かはわかりません。

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

私はエラー" planeGeometry.lookAt is機能ではありません "。 –

+0

THREE_82にTHREE.Geometry.lookAt()が追加されたようです。古いバージョンを使用していますか? – msun

0
var material = ...; 
var plane = new THREE.Plane(...); 

// Align to plane 
var geometry = new THREE.PlaneGeometry(100, 100); 
var mesh = new THREE.Mesh(geometry, material); 
mesh.translate(plane.coplanarPoint()); 
mesh.quaternion.setFromUnitVectors(new THREE.Vector3(0,0,1), plane.normal); 

Plane.coplanarPoint()は単に-normal*constantを返し、「近い」の任意の点で中心を決定するPlane.projectPoint()を使用するより良いオプションかもしれないことに留意されたいです。