2017-05-06 885 views
0

我需要使用颜色突出显示交点并将其投影到平面上。表面与平面(threejs)相交并将其投影到平面XoY(3D)上

EllipticParaboloid:

const init = (a, b) => { 
    return (u, v) => { 
     const height = 100; 
     const size = 5; 

     u = u * height; 
     v = 2 * v * Math.PI; 

     const x = a * size * Math.sqrt(u) * Math.cos(v); 
     const y = u; 
     const z = b * size * Math.sqrt(u) * Math.sin(v); 

     return new Three.Vector3(x, y, z); 
    } 
} 

const ellipticParaboloid = (a, b) => { 
    const geom = new Three.ParametricGeometry(init(a, b), 25, 25); 
    const mat = new Three.MeshPhongMaterial({ color: 0xcc3333a, wireframe: true }); 
    const mesh = new Three.Mesh(geom, mat); 

    return mesh; 
} 

飞机:

const init = (c) => { 
    return (u, v) => { 
     const height = 300; 
     const size = 1; 

     u = u * height; 
     v = v * height; 

     const x = size * u - height/2; 
     const y = c; 
     const z = size * v - height/2; 

     return new Three.Vector3(x, y, z); 
    } 
} 

const levelSurface = (c) => { 
    const geom = new Three.ParametricGeometry(init(c), 25, 25); 
    const mat = new Three.MeshPhongMaterial({ color: 0x00ff0000, wireframe: true }); 
    const mesh = new Three.Mesh(geom, mat); 

    return mesh; 
} 

也许路口的一些公式我能得到什么? 它看起来像这样:http://joxi.ru/L21GRWau5vKzrX 但我需要投射在平面XOY此交汇:http://joxi.ru/RmzozYwcq7aK2O

我可怎么办呢?也许一些例子(这对我来说很好)或者一些材料

回答

1

我不知道是否有一个函数来做到这一点,但我有一种方法可以用数学方法做到这一点。为了得到交点轮廓的投影,首先我们需要得到交点轮廓,其次,得到该交点投影平面上的正交投影。

那么,如何得到交集?从囚犯849有一个不错的answer。我的帖子是建立在他的回答上的。

当我们得到十字路口后,我们需要对它进行投影。我们可以使用正交投影矩阵来做到这一点。我们已经将所有相交点存储在一个数组中,只是使每个点都应用正交投影矩阵,然后将该点转换为平面曲面。

​​

应用矩阵和翻译:

 transformMatrix = getProjectMatrix(mathPlane.normal); 
     for (var i = 0 ; i < pointsOfIntersection.vertices.length ; i++) 
     { 
      projectionGeom.vertices[i] = new THREE.Vector3().copy(pointsOfIntersection.vertices[i]).applyMatrix3(transformMatrix); 
      projectionGeom.vertices[i].addScaledVector(mathPlane.normal , mathPlane.constant * -1); 
     } 

完全jsfiddle例子。

如果你想了解更多关于正射投影的知识,你可以在8.4节看这book

更新:我发现THREE.Vector3具有功能.projectOnPlane (planeNormal),不需要计算投影矩阵,并不再适用,只要在路口轮廓调用这个函数的每个顶点。

希望它有帮助。

+0

我可以制作此项目的功能梯度吗? https://en.wikipedia.org/wiki/Gradient。两个变量的函数,如z = 2x^2 + 3y^2。 – Daxik

+0

现在,我们只是得到投影的轮廓,你需要通过轮廓制作一张单一的脸,然后,将纹理贴到脸上,也许你需要写一个着色器,但是,我不知道如何写一个着色器。 –