11import BESSEL from "bessel"
22import { BESSEL_ZEROS , SUPERPOSITION , EXCITATION } from "./config"
3+ import { toPolar } from "@/common/geometry"
34import {
45 defaultTerms ,
56 defaultScale ,
67 getEffectiveValue ,
7- toPolar ,
8+ getTrig ,
89} from "./helpers"
910
1011// Rectangular plate interference pattern
1112// Domain: [0, 1] or [-1, 1]
1213export function interferenceRectangular ( x , y , opts ) {
1314 const { m, n, superposition, amplitude, boundary } = opts
14- const trig = boundary === "free" ? Math . cos : Math . sin
15+ const trig = getTrig ( boundary )
1516 const mode = SUPERPOSITION [ superposition ]
1617 const term1 = trig ( n * Math . PI * x ) * trig ( m * Math . PI * y )
1718 const term2 = trig ( m * Math . PI * x ) * trig ( n * Math . PI * y )
@@ -34,12 +35,10 @@ export function interferenceRectangular(x, y, opts) {
3435// Domain: x,y in [-1, 1], circular boundary at r=1
3536export function interferenceCircular ( x , y , opts ) {
3637 const { m, n, radial, superposition, amplitude, boundary } = opts
37- const polar = toPolar ( x , y )
38+ const { r , theta } = toPolar ( x , y )
3839
39- if ( ! polar ) return 1000
40-
41- const { r, theta } = polar
42- const trig = boundary === "free" ? Math . cos : Math . sin
40+ if ( r > 1 ) return 1000
41+ const trig = getTrig ( boundary )
4342 const mode = SUPERPOSITION [ superposition ]
4443
4544 // Default terms: two different angular modes, same radial zero
@@ -66,7 +65,7 @@ export function interferenceCircular(x, y, opts) {
6665// frequency scales all harmonics (zoom), modes controls complexity
6766export function harmonicRectangular ( x , y , opts ) {
6867 const { modes, decay, frequency, boundary } = opts
69- const trig = boundary === "free" ? Math . cos : Math . sin
68+ const trig = getTrig ( boundary )
7069 const scaledFreq = frequency * 1.5 - 1
7170 const decayExp = ( decay + 1 ) / 8
7271
@@ -94,11 +93,9 @@ export function harmonicRectangular(x, y, opts) {
9493// modes controls angular complexity, radial controls radial complexity
9594export function harmonicCircular ( x , y , opts ) {
9695 let { modes, radial, decay, frequency } = opts
97- const polar = toPolar ( x , y )
98-
99- if ( ! polar ) return 1000
96+ const { r, theta } = toPolar ( x , y )
10097
101- const { r , theta } = polar
98+ if ( r > 1 ) return 1000
10299 const scaledFreq = frequency * 1.5
103100 const decayExp = ( decay + 1 ) / 16
104101 let sum = 0
@@ -211,11 +208,9 @@ export function excitationRectangular(x, y, opts) {
211208// Loops over angular modes (m) and radial modes (n)
212209export function excitationCircular ( x , y , opts ) {
213210 const { excitation, spread, position, modes, radial, frequency } = opts
214- const polar = toPolar ( x , y )
215-
216- if ( ! polar ) return 1000
211+ const { r, theta } = toPolar ( x , y )
217212
218- const { r , theta } = polar
213+ if ( r > 1 ) return 1000
219214 const spreadFactor = spread / 5
220215 const freq = frequency * 2 - 1
221216 let sum = 0
0 commit comments