JSFiddle - React, Tailwind, and code Playground
HTML
<script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/0.150.0/three.min.js"></script>
Plot:
<span style="color:red">red: drag</span>,
<span style="color:green">green: localSpeed</span>,
<span style="color:blue">blue: lift</span>,
<span style="color:gold">yellow: drag+lift force</span>,
<span style="color:magenta">magenta: attackangle</span>,
<span style="color:gray">white: total</span>,
<span style="color:black">black: rudder angle</span>,
<span style="color:orange">orange: vehicle angle</span>
<br>
<canvas id="plot"></canvas>
<br>
Vectors:
<span style="color:red">red: drag</span>,
<span style="color:green">green: thrust</span>,
<span style="color:blue">blue: lift</span>,
<span style="color:gold">yellow: drag+lift force</span>,
<span style="color:cyan">cyan: rudder normal</span>,
<span style="color:gray">white: total</span>,
CSS
body {
margin: 0px;
}
JavaScript
//import * as THREE from "three";
//import { Euler, Matrix3, Vector3 } from "three";
// colors
const cred = 0xff0000;
const cgreen = 0x00ff00;
const cblue = 0x0000ff;
const cyellow = 0xffff00;
const ccyan = 0x00ffff;
const cmagenta = 0xff00ff;
const cblack = 0x000000;
const cwhite = 0xffffff;
/** degree to radian */
function rad(deg) {
return (deg / 180) * Math.PI;
}
/** radian to degree */
function deg(rad) {
return (rad / Math.PI) * 180;
}
// string of vector components
function vstr(v) {
return `${v.x}, ${v.y}, ${v.z}, `
}
class Vehicle {
constructor(scene) {
this.rudder = 10; // [deg]
this.thrust = 1; // [N]
// this.length = 0.3;
// this.width = 0.15;
this.fMass = 0.0; // total mass
this.mInertia = new THREE.Matrix3(); // mass moment of inertia in body coordinates
this.mInertiaInverse = new THREE.Matrix3(); // inverse of mass moment of inertia
this.vPosition = new THREE.Vector3(0, 0, 0.001); // position in earth coordinates
this.vVelocity = new THREE.Vector3(); // velocity in earth coordinates
this.vVelocityBody = new THREE.Vector3(.0, 0, 0); // velocity in body coordinates
this.vAngularVelocity = new THREE.Vector3(); // angular velocity in body coordinates
this.vEulerAngles = new THREE.Vector3(0, 0, 0); // Euler angles in body coordinates
this.qOrientation = new THREE.Quaternion(); // orientation in earth coordinates
this.qOrientation.setFromEuler(new THREE.Euler().setFromVector3(this.vEulerAngles));
this.vForces = new THREE.Vector3(); // total force on body
this.vMoments = new THREE.Vector3(); // total moment (torque) on body
this.elements = [
{
type: "main",
fMass: 1.0,
vDCoords: new THREE.Vector3(0, 0.0, 0.0),
vCGCoords: null,
vLocalInertia: new THREE.Vector3(.001, .001, .001), // TODO:
rotates: false,
...