Skip to content

Commit ebeb914

Browse files
committed
fix: correct 2D cross product formula in MathUtils
The cross product formula was incorrect: - Before: p1x * p2x - p1y * p2y (wrong) - After: p1x * p2y - p1y * p2x (correct) The 2D cross product (perp dot product) should compute: A × B = Ax * By - Ay * Bx This returns the z-component of the 3D cross product when treating 2D vectors as 3D vectors with z=0. Also fixed the example comment to show correct result.
1 parent 48f15d1 commit ebeb914

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

src/utils/MathUtils.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ export const lerp = mix;
5656
* @param p2y 第二个向量的y分量
5757
* @returns 叉积结果 (标量)
5858
* @example
59-
* cross(1, 0, 0, 1) // 返回 0
59+
* cross(1, 0, 0, 1) // 返回 1
6060
*/
6161
export function cross(
6262
p1x: number,
@@ -68,7 +68,7 @@ export function cross(
6868
if (!isNumber(p1x) || !isNumber(p1y) || !isNumber(p2x) || !isNumber(p2y)) {
6969
throw new Error("Invalid parameters for cross function");
7070
}
71-
return p1x * p2x - p1y * p2y;
71+
return p1x * p2y - p1y * p2x;
7272
} catch (error) {
7373
console.error("Error in cross function:", error);
7474
return 0;

0 commit comments

Comments
 (0)