faces
方法用于获取一个多面体的所有面,返回所有面的数组。每个面是一个由索引组成的数组,每个索引对应于多面体的一个点。
faces(polyhedron)
polyhedron
:多面体对象。const vertices = [
[-1, 0, 1],
[1, 0, 1],
[1, 0, -1],
[-1, 0, -1],
[0, 1, 0],
[0, -1, 0]
];
const faces = [
[0, 1, 4],
[1, 2, 4],
[2, 3, 4],
[3, 0, 4],
[1, 0, 5],
[2, 1, 5],
[3, 2, 5],
[0, 3, 5]
];
const polyhedron = { vertices, faces };
const allFaces = faces(polyhedron);
console.log(allFaces);
输出结果:
[
[0, 1, 4],
[1, 2, 4],
[2, 3, 4],
[3, 0, 4],
[1, 0, 5],
[2, 1, 5],
[3, 2, 5],
[0, 3, 5]
]
polyhedron
参数缺失,将抛出一个 TypeError
异常:Cannot read property 'length' of undefined
。polyhedron
参数不是一个对象,将抛出一个 TypeError
异常:polyhedron is not an object
。polyhedron
对象没有 vertices
属性或 faces
属性,将抛出一个 TypeError
异常:polyhedron is not a polyhedron object
。