MCPcopy Index your code
hub / github.com/graphif/project-graph / splitVector

Method splitVector

packages/data-structures/src/Vector.ts:195–205  ·  view source on GitHub ↗

* 将自己方向的单位向量分解成一堆向量,就像散弹分裂子弹一样 * 返回的都是单位向量 * * 根据散弹数量和间隔角度,计算出每个散弹的方向单位向量 * 做法是先依次生成 bulletCount 个向量,每个间隔角度为 bulletIntervalDegrees,顺时针旋转 * 第一个生成的向量恰好就是攻击方向。 * 最后再整体 逆时针旋转总角度的一半,得到每个向量最终的方向向量

(splitCount: number, splitDegrees: number)

Source from the content-addressed store, hash-verified

193 * 最后再整体 逆时针旋转总角度的一半,得到每个向量最终的方向向量
194 */
195 splitVector(splitCount: number, splitDegrees: number): Vector[] {
196 let vectors: Vector[] = [];
197 const selfNormalized = this.normalize();
198 for (let i = 0; i < splitCount; i++) {
199 vectors.push(selfNormalized.rotateDegrees(i * splitDegrees));
200 }
201 // 计算最终需要的总偏移角度
202 const totalOffsetDegrees = ((splitCount - 1) * splitDegrees) / 2;
203 vectors = vectors.map((d) => d.rotateDegrees(-totalOffsetDegrees));
204 return vectors;
205 }
206
207 /**
208 * 计算两个点的中心点

Callers

nothing calls this directly

Calls 3

normalizeMethod · 0.95
rotateDegreesMethod · 0.80
pushMethod · 0.45

Tested by

no test coverage detected