File tree Expand file tree Collapse file tree
packages/layerchart/src/lib/utils Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -190,3 +190,47 @@ export function getSpiral({
190190 } ;
191191 } ) ;
192192}
193+
194+ interface SineWaveOptions {
195+ numPoints : number ;
196+ frequency ?: number ;
197+ amplitude ?: number ;
198+ noiseLevel ?: number ;
199+ phase ?: number ;
200+ xMin ?: number ;
201+ xMax ?: number ;
202+ }
203+
204+ export function generateSineWave ( options : SineWaveOptions ) {
205+ const {
206+ numPoints,
207+ frequency = 1 ,
208+ amplitude = 1 ,
209+ noiseLevel = 0 ,
210+ phase = 0 ,
211+ xMin = 0 ,
212+ xMax = 2 * Math . PI ,
213+ } = options ;
214+
215+ if ( numPoints <= 0 ) {
216+ throw new Error ( 'Number of points must be greater than 0' ) ;
217+ }
218+
219+ const points : { x : number ; y : number } [ ] = [ ] ;
220+ const xStep = ( xMax - xMin ) / ( numPoints - 1 ) ;
221+
222+ for ( let i = 0 ; i < numPoints ; i ++ ) {
223+ const x = xMin + i * xStep ;
224+
225+ // Generate base sine wave
226+ const sineValue = amplitude * Math . sin ( frequency * x + phase ) ;
227+
228+ // Add random noise if specified
229+ const noise = noiseLevel > 0 ? ( Math . random ( ) - 0.5 ) * 2 * noiseLevel : 0 ;
230+ const y = sineValue + noise ;
231+
232+ points . push ( { x, y } ) ;
233+ }
234+
235+ return points ;
236+ }
You can’t perform that action at this time.
0 commit comments