Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの 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 件 担当者 0 名 GitHub で見る

メンテナーはふだん 2 日以内に返信

@Aman-goel-04 がすでに取り組んでいます。

2026年7月25日 から。

評価

難易度
3/5
見積もり時間
1〜2日
初心者へのやさしさ
72/100
issue の種類
バグ
明瞭さ
おおむね明確
活発さ
静か
技術スタック
javascript

調査の方向性

Issue に記載されているインスタンスおよび static の 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時間
マージ済み PR(30日)
29

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

processing/p5.js のほかの issue

processing/p5.js の issue をすべて見る

似ている issue

JavaScript の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。