Skip to content

[p5.js 2.0+ Bug Report]: Vector.lerp() is hard coded to use three dimensions #8927

@sidwellr

Description

@sidwellr

Most appropriate sub-area of p5.js?

  • Accessibility
  • Color
  • Core/Environment/Rendering
  • Data
  • DOM
  • Events
  • Image
  • IO
  • Math
  • Typography
  • Utilities
  • WebGL
  • WebGPU
  • p5.strands
  • Build process
  • Unit testing
  • Internationalization
  • Friendly errors
  • Other (specify if possible)

p5.js version

2.3.0

Web browser and version

Brave 1.90.122

Operating system

Linux Mint 22.1

Steps to reproduce this

Steps:

  1. Create two 4D vectors
  2. Use lerp() to interpolate between the two
  3. Note the result only works for the first three dimensions

Snippet:

function setup() {
  let v1 = createVector(0, 1, 0, 1);
  let v2 = createVector(1, 0, 1, 0);
  v1.lerp(v2, 0.5);
  
  // v1 should be vector[0.5, 0.5, 0.5, 0.5], but is actually vector[0.5, 0.5, 0.5, 1]
  print(v1.toString());
}

Discussion

lerp() currently computes x, y, and z individually. To extend to vectors of any dimension, other vector methods can be used, like p5.Vector.add(v1, p5.Vector.sub(v2, v1).mult(c)). Of course, this needs to be adapted to both the instance and static methods.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    Status
    No status

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions