Ask Your Question
0

What is the method for obtaining the position of the center vertex for all faces in BoxGeometry using threejs?

asked 2022-01-13 11:00:00 +0000

lalupa gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2021-11-01 10:00:00 +0000

plato gravatar image

To obtain the position of the center vertex for all faces in BoxGeometry using threejs, you can use the following method:

const box = new THREE.BoxGeometry();

for (let i = 0; i < box.faces.length; i++) {
    const face = box.faces[i];
    const v1 = box.vertices[face.a];
    const v2 = box.vertices[face.b];
    const v3 = box.vertices[face.c];

    // Calculate the centroid of the face
    const center = new THREE.Vector3();
    center.add(v1).add(v2).add(v3).divideScalar(3);

    console.log(center);
}

This code loops through all the faces of the BoxGeometry and calculates the centroid of each face using the three vertices that make up the face. The centroid is calculated by adding the three vertices together and dividing by three. The resulting center vector represents the position of the center vertex for that particular face. The center vector is then logged to the console for each face.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2022-01-13 11:00:00 +0000

Seen: 18 times

Last updated: Nov 01 '21