Miscalculation of Volume when Subdivisions are set to 0

After reaching out for help on Volume Calculation, I found valuable assistance in this specific thread. Since then, I've developed a function that accurately calculates the volume of a closed mesh using Three JS. In my implementation, the variable face4 determines whether the face is divided into two triangles, specifically for Face3 meshes. The majority of my geometry involves custom Face4 construction.

function volumeCalc(object, face4){

    if (face4 == false) {

        for (var i=0; i<object.geometry.faces.length; i++) {

            var pA = (object.geometry.faces[i].a);
            var qA = (object.geometry.faces[i].b);
            var rA = (object.geometry.faces[i].c);

            // More calculations here...

        }
        
    } else {
    
        for (var i=0; i<object.geometry.faces.length; i++) {

            var pA = (object.geometry.faces[i].b);
            var qA = (object.geometry.faces[i].c);
            var rA = (object.geometry.faces[i].d);

            // More calculations here...

        }
        
    }
    
    // Additional calculations...
    
}

This solution is based on the following formula:

pv =  Px*Qy*Rz + Py*Qz*Rx + Pz*Qx*Ry - Px*Qz*Ry - Py*Qx*Rz - Pz*Qy*Rx;

Prior to creating the mesh, I execute the following operations on THREE.Geometry:

geom.mergeVertices();
geom.computeCentroids();
geom.computeFaceNormals();
geom.computeVertexNormals();

// Subdivision modifier
var modifier = new THREE.SubdivisionModifier( x );
modifier.modify( geom );

The volume calculation works accurately when x > 0 and subdivision is applied. However, discrepancies arise when x = 0 or there is no subdivision.

Any suggestions or insights on improving the function for broader usage would be greatly appreciated. This marks my initial endeavor towards open-source contribution. Thank you for your feedback.

Answer №1

Can we confirm if "x" is a custom variable created by the user? If it evaluates to 0, then the geometry should not be subjected to the subdivision modifier.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

A guide on incorporating unique font weights into Material UI

Looking to customize the Material theme by incorporating my own font and adjusting the font weights/sizes for the Typography components. I am attempting to set 100/200/300/400/500/600/700 as options for each specific typography variant, but it seems that o ...

Personalized jQuery Slider, Go back to initial slide

Working on enhancing my jQuery skills by constructing a basic slider with 3 slides. The slider wrapper, with a fixed width of 1400px and a height of 350px serves as the outer container. Within this wrapper lies an unordered list where its items are floate ...

How to manage form submissions in Vue.js using inputs within child components

I'm working on a parent component that acts as a form. This form consists of multiple child components, each containing input fields. <template> <div class="form"> <generalData v-model="input" /> <textAreas v- ...

Access values in object array without iterating over it

I'm wondering if there is a way to extract the values of the name property from an object array without having to iterate through it. var objArray = [ { name: 'APPLE', type: 'FRUIT' }, { name: 'ONION', t ...

"What is the best way to include additional fields within a popover in an AngularJS application

This is my code for implementing a popover using AngularJS. I am trying to figure out how to add custom styling to the popover HTML, but I am having trouble binding elements in that part of the code. <!DOCTYPE html> <html> <head> <l ...

The onsubmit function is not successfully executing the JavaScript function

This code contains a form for creating a new user login. Upon pressing the 'continue' button, it is supposed to call the 'validateForm()' function which checks the values entered in the form. However, even when there are errors such as ...

Sending a parameter from a click event to a function

Struggling with a jQuery and AJAX issue all night. I am new to both and trying to implement something similar to this example. I have an edit button with the ID stored in a data-ID attribute. Here's an example of what my button looks like: <butto ...

How to eliminate a specific value from an array with the help of JavaScript

https://i.sstatic.net/7QG1J.png I'm working with an array in JavaScript and I need to remove a specific value from it, specifically the one named "PropertyType[]". Can anyone help me figure out how to do this? I've included a picture of the arra ...

The Google Maps JavaScript API is displaying a map of China instead of the intended location

After multiple attempts, I am still facing an issue with setting up the Google Map on my website. Despite inputting different coordinates, it consistently shows a location in China instead of the intended one. Here is the code snippet that I have been usin ...

Explaining Vue.js actions and mutations in detail

Can someone help clarify the relationship between these functions for me? I'm currently learning about Vue.js and came across an action that commits a mutation. The Action: updateUser({commit}, user) { commit('setUser', {userId: user[&ap ...

In AngularJS, showcasing five elements at a time from an array containing 'n' items before looping back to the beginning

I'm a beginner in AngularJS and facing a scenario where I need to display 5 items from an array containing multiple items. The requirement is to initially show items 1-5 and then, after 2-3 seconds, add a 6th item at the top and remove the last item f ...

Error occurs in Windows script while running a project installed globally

Upon installing my project globally, I encountered a Windows Script Host error. https://i.stack.imgur.com/unFVu.png What steps can I take to resolve this issue? The following is my JavaScript code snippet: Object.defineProperty(exports, "__esModule ...

Is it not possible to access the profile page using the GET method?

I am currently using Express.js to display user input in the URL after submitting a form and redirecting the user to their profile page with their name in the URL. To achieve this, I utilized req.query and the GET method. var express = require('expre ...

The NextJS API is throwing an error due to a mysterious column being referenced in

I am currently in the process of developing an API that is designed to extract data from a MySQL table based on a specific category. The code snippet below represents my current implementation: import { sql_query } from "../../../lib/db" export ...

Ways To Obtain Trustworthy Dates Using JavaScript

Last week, I encountered an intriguing issue at my job. I needed to obtain a date accurately using JavaScript, but the code I was working with utilized new Date() which resulted in discrepancies due to some customers having incorrect system time settings. ...

Issues encountered when trying to achieve transparency in three.js across various scenes

I've been using multiple scenes to achieve selective lighting, but I've run into an issue with transparent objects. To keep it simple, I've created a jsfiddle example: [1]: https://jsfiddle.net/curisiro/w9ke75ma/2/ In my setup, I have two ...

Navigate to a local server running on localhost:3000 and access the external URL www.google.com

When attempting to access an external URL, the website that should open in a new tab is redirecting to http://localhost:3001/www.google.com instead of www.google.com. <IconButton key={index} size="large" color="primary" href={e.url ...

Use the button to trigger the opening of the datepicker in React material UI

Currently, I am incorporating a Datepicker in my project using React Material UI. <TextField id="datetime-local" label="Next appointment" type="datetime-local" defaultValue="2017-05-24T ...

A function containing a JavaScript Event Listener for better encapsulation

I am encountering an issue with an event listener inside a function where both the listener and emitter are within the same function scope. Upon triggering the event, a variable is supposed to increment. However, when I call the function multiple times, t ...

I am encountering an error that states: UnhandledPromiseRejectionWarning: TypeError: Unable to retrieve the property 'buffer' as it is undefined

I am facing an issue with my code where I am unable to upload new files to my website. Can someone help me understand what might be causing this problem? const multer = require("multer"); const upload = multer({ storage: multer.memoryStorage() ...