Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

[p5.js 2.0+ Bug Report]: Vector.slerp() does not work correctly for vectors of more than three dimensions

未关闭
#8,928 7 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 2 天内回复

@Aman-goel-04 已经在做这个了。

开始于 2026年7月25日。

评估

难度
3/5
预计耗时
1-2 天
新手友好度
72/100
Issue 类型
缺陷
描述清晰度
基本清楚
活跃度
冷清
技术栈
javascript

调研方向

从 issue 中描述的实例和静态 p5.Vector.slerp() 入口开始,然后重现所提供的 4D 示例。将当前基于 cross() 的行为与所提议的通用 slerp 公式进行比较,同时检查 2D 和 3D 结果保持不变。当 4D 插值产生预期的向量,并且现有的低维行为得到保留时,即表示完成。

由索引模型根据 Issue 内容生成。

描述

Area:Math p5.js 2.0+
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 slerp() to interpolate between the two
  3. Note the result is incorrect
Snippet:
function setup() {
  let c = 0.5;
  let v1 = createVector(0, 1, 0, 1);
  let v2 = createVector(1, 0, 1, 0);
  v1.slerp(v2, 0.5);
  
  // v1 should be vector[0.707, 0.707, 0.707, 0.707] but is actually vector[0.5, 0.707, 0.5, 1]
  print(v1.toString());
}
Discussion

slerp() currently uses cross() for its computation, which is only defined for 3D vectors. It needs to use a more general formula, which is readily available on the web; search for "slerp formula".

Feel free to adapt the following (to both the instance and static methods). In my brief testing, it gives the same result as the current slerp() for 2D and 3D vectors, and also seems to work correctly for 4D vectors. It can certainly be optimized.

function slerp(v0, v1, t) {
  let m = v0.mag() + (v1.mag() - v0.mag()) * t;
  let r0 = p5.Vector.normalize(v0);
  let r1 = p5.Vector.normalize(v1);
  let a = acos(r0.dot(r1));
  if (a === 0) {
    return p5.Vector.add(v0, p5.Vector.sub(v1, v0).mult(t));
  } else {
    r0.mult(sin((1 - t) * a) / sin(a));
    r1.mult(sin(t * a) / sin(a));
    return r0.add(r1).mult(m);
  }
}
主要语言
JavaScript
星标
24.1k
派生
3.9k
平均合并
3 天 4 小时
30 天内合并 PR
29

环境准备

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

processing/p5.js 的其他 Issue

查看 processing/p5.js 的全部 Issue

相似的 Issue

更多 JavaScript Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。