Trying to create a simulation of a steerable vehicle, like a plane, hovercraft, or boat, in either a gas or liquid fluid (such as air or water).
The JavaScript code is based on the 3D rigid body airplane simulator from Physics for Game Developers, adapted to use Three.js
's Vector3
, Matrix3
, and Quaternion
classes.
When thrust force is applied to the vehicle, it accelerates and moves through the medium. The speed results in drag and lift forces on a control surface or "rudder", depending on its angle.
This generates a force offset from the common center of gravity of the vehicle parts (main and rudder), leading to angular motion (steering) due to torque.
The drag and lift forces are proportional to the speed squared.
Therefore, drag limits the maximum speed achievable with a given thrust force.
In a state of steady motion (no acceleration), all forces balance each other out, meaning that drag and lift oppose and equal the thrust force.
This equilibrium can lead to oscillations in the system, which can be stable or cause the simulation to "explode" depending on certain parameters.
Oscillation usually occurs when the normal vector of the control surface and the drag vector become perpendicular, resulting in a zero dot product that affects the angle of attack.
This issue tends to arise more prominently with:
- lower
RHO
values (impacting both lift and drag) - decreased lift coefficient
lc
- increased drag coefficient
dc
(higher drag means less acceleration and speed)
To observe this problem more clearly, you can view a demonstration at: https://jsfiddle.net/ghcse56f/ (easier to interact with compared to snippets here on SO)
It also includes a basic plot of some values (at different scales). The calculation of lift and drag starts around line 215.
What is causing this issue and how can it be resolved?
I've made adjustments to the demo by using a lift coefficient that varies with the angle of attack, reducing the drag coefficient, and increasing RHO - however, the simulation breaks down in step 227.