使用方程和/或矢量在三维空间中绘制二维平面

Graphing 2d plane in 3d space using equation and/or vectors

本文关键字:绘制 平面 二维 三维空间 方程      更新时间:2023-09-26

我正在尝试为一个数学项目制作一个线性回归平面可视化工具。目前我已经完成了数学部分,但我不知道如何绘制平面图。我有一个z=C+xD+yE形式的方程,其中C、D和E是已知的常数。如何使用这些信息绘制平面图?谢谢

github页面:https://saxocellphone.github.io/LAProject/

 z=C+xD+yE

这个方程式给出了关于飞机的全部信息。你还需要什么来绘制它?可能这取决于你的图形软件的可能性。给定方程的正则形式:

 xD + yE - z + C = 0

平面的法线为(D, E, -1)。到坐标原点Abs(C)/Sqrt(D^2+E^2+1)的距离。

平面与坐标轴相交的值为(-C/D), (-C/E), (C)

我知道你的问题不是数学,而是三,正如WestLangley在他的评论中指出的那样,你可以玩旋转等游戏,或者创建一个简单的三角形,这是最简单的方法

既然你有了平面的方程式,就可以创建3个点来形成一个三角形

// z=C+xD+yE
// i assume here that the plane is not aligned with any axis 
// and does not pass through the origin, otherwise choose the points in another way
var point1 = new THREE.Vector3(-C/D,0,0);//x axis intersection
var point2 = new THREE.Vector3(0,-C/E,0);//y axis intersection
var point3 = new THREE.Vector3(0,0,C);//z axis intersection

现在形成一个新的几何体,如如何在three.js 中制作自定义三角形

var geom = new THREE.Geometry(); 
geom.vertices.push(point1);// adding vertices to geometry
geom.vertices.push(point2);
geom.vertices.push(point3);
// telling geometry that vertices 0,1,2 form a face = triangle
geom.faces.push( new THREE.Face3( 0, 1, 2 ) ); 

创建一个简单的材质并将其添加到场景中

var material = new THREE.MeshBasicMaterial({
    color: 0xff0000, // RGB hex color for material
    side: THREE.DoubleSide // do not hide object when viewing from back
});
scene.add(new THREE.Mesh(geometry,material));

这应该会让你开始,你可以添加另一个三角形,或者通过选择距离

更远的点使其更大