Skip to content

Instantly share code, notes, and snippets.

@Hypnotriod
Last active February 15, 2024 10:07
Show Gist options
  • Save Hypnotriod/fae1fd6774cd39c858e96e8aea10841d to your computer and use it in GitHub Desktop.
Save Hypnotriod/fae1fd6774cd39c858e96e8aea10841d to your computer and use it in GitHub Desktop.
2 wheel vehicle trajectory calculation
// --------------------------------
// vehicle is faced towards y axis
// start angle
const A = -Math.PI*0.5
// start x position
const X = 2
// start y position
const Y = 0
// wheels distance
const L = 1
// left wheel velocity
const v1 = Math.PI * 0.99
// right wheel velocity
const v2 = Math.PI * 1
// --------------------------------
// angular velocity of the wheels center
const a = (v2 - v1) / L
// velocity of the wheels center
const v = (v1 + v2) / 2
// radius
const r = a != 0 ? v / a : 0
// next relative x position
const x1 = a != 0 ? Math.cos(a) * r - r : 0
// next relative y position
const y1 = a != 0 ? Math.sin(a) * r : v
// next x position
const x = Math.cos(A)*x1 - Math.sin(A)*y1 + X
// next y position
const y = Math.sin(A)*x1 + Math.cos(A)*y1 + Y
// --------------------------------
console.log('velocity', v)
console.log('angle', (a + A) / Math.PI * 180)
console.log('radius', r)
console.log('x', x.toFixed(3))
console.log('y', y.toFixed(3))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment