Utilizing PhysiJS for obtaining linear velocity at a specific point on a rotating object

Is there a way to calculate the linear velocity (relative to world space) of a point on an object in PhysiJS, utilizing the object's linear and angular velocity?

I considered creating an invisible vertex on the object for this task, but it seems like the API doesn't support that functionality. Do I have to manually calculate it based on the translational and rotational velocity of the object? (And if so, does THREE.js or PhysiJS provide a straightforward method for doing so?)

Starting from the basics:

  • Given object.position (1)
  • Given the position of the point in world space object.localToWorld(point) (2)
  • Given object.getLinearVelocity() (3)
  • Given object.getAngularVelocity() (4)

Therefore, I need to:

  • Subtract (1) from (2) to find the point's offset in world space (5)
  • Utilize (4) and (5) to determine the linear velocity of the point relative to the object (6)
  • Add (6) and (3) to obtain the total linear velocity of the point

To achieve the first and third steps, I can utilize Three.js's Vector3 methods .sub(Vector3) and .add(Vector3). However, the middle operation is challenging me, although I suspect it involves some form of multiplication. What operation should I employ, considering that (4) can be either a Euler angle or a Quaternion?

My familiarity with matrices is quite limited (and rusty!), and I have no experience with quaternions.

You can access Three.js's API documentation here.

Thank you!

Answer №1

Finally! Successfully resolved the issue. Here is a more versatile version that doesn't rely on PhysiJS. Simply replace the vectors with those from PhysiJS.

scene.add(point2);
scene.add(pointAxis);
pointAxis.add(point);

angularVelocity = new THREE.Vector3( 0, 0, 0.01);

function animate(){

    // rotate point around pointAxis
    pointAxis.rotation = pointAxis.rotation.add(angularVelocity);

    // calculate position of point in world space
    var pointPosWorld = pointAxis.localToWorld(point.position.clone());

    // calculate position of point in world relative to fulcrum
    var pointOffsetPos = new THREE.Vector3();
    pointOffsetPos = pointPosWorld.sub(pointAxis.position.clone());

    // Calculate tangential velocity
    tangentialVelocity = rotate.clone().cross(pointOffsetPos);

}

I reached this solution after finding guidance here on the physics stack exchange site.

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

Dynamically delete a property from a JSON object

I am currently working on a task that involves removing properties from a JSON object. I need to create a system where I can specify an array of locations from which the fields should be redacted. The JSON request I am dealing with looks like this: { "nam ...

Creating a variable by using a conditional operation in JavaScript

When the statement <code>name = name || {} is used, it throws a reference error. However, using var name = name || {} works perfectly fine. Can you explain how variable initialization in JavaScript functions? ...

Having trouble with the JSFiddle dropdown button that is unresponsive to

I am currently in the process of developing a test drop-down menu. The open menu button functions correctly, however, the close button is unresponsive to clicking or hovering actions. Upon clicking the open menu button, it should make the other button visi ...

Dynamically access nested objects by utilizing an array of strings as a pathway

Struggling to find a solution for accessing nested object properties dynamically? The property path needs to be represented as an array of strings. For example, to retrieve the label, use ['type', 'label'] I'm at a roadblock wit ...

chosen selection from AngularJS dropdown

I'm really struggling with something. Currently, I am working on a web app using AngularJS where I have created a table displaying database results. Each row in the table contains a select item loaded with a model. However, I am unsure how to mark a ...

Having trouble changing my array state in react?

I'm having trouble understanding why my React state isn't updating with the following code: state = { popUpMessages:[] } popUpMessage(id,name) { console.log("id ",id,"name ",name) const addUserObject = { id, name }; const new ...

Node.js Express Issue: Module Not Found

Having trouble launching an express app in docker with node 10.9.0 due to an import problem: root@e85495ae1c9e:/usr/app/backend# node app.js internal/modules/cjs/loader.js:583 throw err; ^ Error: Cannot find module '/usr/app/backend/models/todo&ap ...

JavaScript math validations not functioning correctly

This new project I've been working on involves presenting a multiplication problem and notifying the user if their answer is correct through an alert. The issue arises when the program incorrectly verifies the answers. Take a look at the code: < ...

A method to use jQuery to replace newlines with commas in user input

Input Processing Challenge <input> Whenever there is multi-line text pasted into the input field, I need to replace newlines (\r, \n, and \r\n) as well as tabs \t with commas ,. This scenario mainly occurs when users copy c ...

Instructions for deploying a node application with modules

While working on deploying a node app with node modules to an embedded system, I have been facing challenges with the size of node modules. Whenever I run npm install, it not only downloads the necessary sources but also includes additional files. For exa ...

"Learn how to transfer a selected value from a parent ASP.NET dropdownlist to a textbox in a popup window using JavaScript

I'm struggling to pass the value from a dropdown list in the parent ASPX form to a textbox in the child ASPX form. Parent JavaScript: The first script is used to open the popup window <script type="text/javascript"> var popup; ...

Is there a way to create a JavaScript function that relies on a successful form submission?

After attempting to modify a post on Stack Overflow, I am facing issues with my JavaScript code. As a beginner, it's possible that I overlooked something in the code causing it not to work as expected. The project I'm working on involves creatin ...

When using jQuery and AJAX together, it seems that the POST method is returning

Currently experimenting with Cloud9. The current project involves creating an image gallery. On the initial page: There are a few pictures representing various "categories". Clicking on one of these will take you to the next page showcasing albums fro ...

Ensure execution post completion of evalAsync process

I am relatively new to working with JavaScript and Angular technology. I have encountered a situation where two separate pieces of code are running in different callbacks, triggered by third-party libraries (specifically Kendo UI library callbacks). One f ...

Build a photo carousel similar to a YouTube channel

Is there a way to create an image slider similar to the one on YouTube channels? I've noticed that when there are multiple videos on a channel, YouTube displays them in a slider with back and forth buttons to navigate through the videos that aren&apos ...

The steps to view the JavaScript file of a website using a web browser's inspector tool

As I was exploring the web browser inspector tool, I attempted to view the JavaScript source code of a website (). However, all I could find was HTML code (view-source:). I am eager to access the JS file from my browser directly. How can I achieve this? I ...

unable to render a vector layer in openlayers 6

Currently, I am facing an issue with displaying a vector layer on an openlayers map using the source of local geojson and gpx files in my Vuejs project. Unfortunately, even when testing outside of Vue.js, the vector layer is not being displayed. Here is t ...

The functionality of the Node.js/Express.js app is limited to operating solely on Port 3000

I'm currently troubleshooting an issue with my Node.js/Express.js app running on my server. It seems to only work on port 3000, and I'm trying to understand why. Here's what I've discovered: When I don't specify a port (app.liste ...

Overwriting Resolved Data in Angular UI-Router Child States

I'm facing an issue where the resolve function is the same in both parent and child states, but I need it to return different values based on the child state. Instead of customizing the implementation for each state, it seems to be inheriting the beha ...

Preventing the reoccurrence of function events

I need to create an event triggered by a mouse click when the user clicks a button. The code snippet below shows my attempt, but I'm facing an issue where the function continues to run if the user clicks on a second input field after the initial one: ...