Skip to content

Commit

Permalink
Add vec2.sinwave
Browse files Browse the repository at this point in the history
  • Loading branch information
baku89 committed Feb 24, 2024
1 parent a46d2a8 commit 883eeec
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/scalar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -496,6 +496,19 @@ export namespace scalar {
return (-Math.cos(v) + 1) / 2
}

/**
* Returns a sine wave with the given period. The output ranges from 0 to 1, and y = 0 when x = 0.
*
* @see https://www.geogebra.org/calculator/d3grfqqe
* @param v the input value
* @param period the period of the wave
* @category Periodic Functions
*/
export function sinwave(v: number, period = 1): number {
v = (v * Math.PI * 2) / period
return (-Math.sin(v) + 1) / 2
}

/**
* Returns whether or not the numbers have approximately the same.
*
Expand Down

0 comments on commit 883eeec

Please sign in to comment.