Skip to content

Instantly share code, notes, and snippets.

@Hypnotriod
Last active February 15, 2024 10:07

Revisions

  1. Hypnotriod revised this gist Feb 15, 2024. 1 changed file with 2 additions and 6 deletions.
    8 changes: 2 additions & 6 deletions 2-wheel-vehicle.js
    Original file line number Diff line number Diff line change
    @@ -1,7 +1,3 @@
    function precisionRound(number, precision) {
    var factor = Math.pow(10, precision);
    return Math.round(number * factor) / factor;
    }
    // --------------------------------
    // vehicle is faced towards y axis
    // start angle
    @@ -35,5 +31,5 @@ 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', precisionRound(x,3))
    console.log('y', precisionRound(y,3))
    console.log('x', x.toFixed(3))
    console.log('y', y.toFixed(3))
  2. Hypnotriod revised this gist Oct 22, 2022. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion 2-wheel-vehicle.js
    Original file line number Diff line number Diff line change
    @@ -29,7 +29,7 @@ const x1 = a != 0 ? Math.cos(a) * r - r : 0
    const y1 = a != 0 ? Math.sin(a) * r : v
    // next x position
    const x = Math.cos(A)*x1 - Math.sin(A)*y1 + X
    // nexty y position
    // next y position
    const y = Math.sin(A)*x1 + Math.cos(A)*y1 + Y
    // --------------------------------
    console.log('velocity', v)
  3. Hypnotriod revised this gist Oct 22, 2022. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion 2-wheel-vehicle.js
    Original file line number Diff line number Diff line change
    @@ -30,7 +30,7 @@ const y1 = a != 0 ? Math.sin(a) * r : v
    // next x position
    const x = Math.cos(A)*x1 - Math.sin(A)*y1 + X
    // nexty y position
    const y = Math.sin(A)*x1 - Math.cos(A)*y1 + Y
    const y = Math.sin(A)*x1 + Math.cos(A)*y1 + Y
    // --------------------------------
    console.log('velocity', v)
    console.log('angle', (a + A) / Math.PI * 180)
  4. Hypnotriod created this gist Oct 22, 2022.
    39 changes: 39 additions & 0 deletions 2-wheel-vehicle.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,39 @@
    function precisionRound(number, precision) {
    var factor = Math.pow(10, precision);
    return Math.round(number * factor) / factor;
    }
    // --------------------------------
    // 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
    // nexty 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', precisionRound(x,3))
    console.log('y', precisionRound(y,3))