Skip to content

Commit 1b1b0c7

Browse files
committed
feat(dotProduct): Added dot-product function
1 parent 6e11ca2 commit 1b1b0c7

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

src/dot-product.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/**
2+
* Compute the dot product of any pair of 2D vectors.
3+
*
4+
* @param {number} x0 - First x start position.
5+
* @param {number} y0 - First y start position.
6+
* @param {number} x1 - First x end position.
7+
* @param {number} y1 - First y end position.
8+
* @param {number} x2 - Second x start position.
9+
* @param {number} y2 - Second y start position.
10+
* @param {number} x3 - Second x end position.
11+
* @param {number} y3 - Second y end position.
12+
* @return {number} Dot product.
13+
*/
14+
function dotProduct (x0, y0, x1, y1, x2, y2, x3, y3) {
15+
let dx0 = x1 - x0
16+
let dy0 = y1 - y0
17+
let dx1 = x3 - x2
18+
let dy1 = y3 - y2
19+
20+
return dx0 * dx1 + dy0 * dy1
21+
}
22+
23+
export { dotProduct }

src/math-toolbox.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,3 +49,4 @@ export { smoothMin } from './smooth-min'
4949
export { smoothMax } from './smooth-max'
5050
export { deltaTime } from './delta-time'
5151
export { gcd } from './gcd'
52+
export { dotProduct } from './dot-product'

0 commit comments

Comments
 (0)