Skip to content

Commit

Permalink
Add chromatic dispersion support in GRIN glass
Browse files Browse the repository at this point in the history
  • Loading branch information
ricktu288 committed Jul 26, 2024
1 parent b4c8b27 commit c43507c
Show file tree
Hide file tree
Showing 16 changed files with 20 additions and 20 deletions.
2 changes: 1 addition & 1 deletion simulator/js/ObjBar.js
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ class ObjBar {
supSubsRequireOperand: true,
charsThatBreakOutOfSupSub: '+-=<>',
autoSubscriptNumerals: true,
autoCommands: 'pi theta sqrt sum',
autoCommands: 'pi theta lambda sqrt sum',
autoOperatorNames: 'sin cos tan sec csc cot sinh cosh tanh log exp arcsin arccos arctan asin acos atan arcsinh arccosh arctanh asinh acosh atanh floor round ceil trunc sign sgn max min abs',
maxDepth: 10,
handlers: {
Expand Down
10 changes: 5 additions & 5 deletions simulator/js/objs/BaseGrinGlass.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ class BaseGrinGlass extends BaseGlass {
}

getRefIndexAt(point, ray) {
return this.fn_p({ x: point.x, y: point.y });
return this.fn_p({ x: point.x, y: point.y, z: ray.wavelength || GREEN_WAVELENGTH });
}

onRayEnter(ray) {
Expand All @@ -105,12 +105,12 @@ class BaseGrinGlass extends BaseGlass {
initFns() {
this.error = null;
try {
this.p = parseTex(this.refIndexFn).toString().replaceAll("\\cdot", "*").replaceAll("\\frac", "/");
this.p = parseTex(this.refIndexFn.replaceAll("\\lambda", "z")).toString().replaceAll("\\cdot", "*").replaceAll("\\frac", "/");
this.p_der_x = math.derivative(this.p, 'x').toString();
this.p_der_x_tex = math.parse(this.p_der_x).toTex().replaceAll("{+", "{"); // 'evaluateLatex' function can't and can handle expressions of the form '...num^{+exp}...' and '...num^{exp}...', respectively, where num and exp are numbers
this.p_der_y = math.derivative(this.p, 'y').toString();
this.p_der_y_tex = math.parse(this.p_der_y).toTex().replaceAll("{+", "{");
this.fn_p = evaluateLatex(this.shiftOrigin(this.refIndexFn));
this.fn_p = evaluateLatex(this.shiftOrigin(this.refIndexFn.replaceAll("\\lambda", "z")));
this.fn_p_der_x = evaluateLatex(this.shiftOrigin(this.p_der_x_tex));
this.fn_p_der_y = evaluateLatex(this.shiftOrigin(this.p_der_y_tex));
} catch (e) {
Expand Down Expand Up @@ -262,8 +262,8 @@ class BaseGrinGlass extends BaseGlass {
const x_der_s_prev = (p2.x - p1.x) / len;
const y_der_s_prev = Math.sign(p2.y - p1.y) * Math.sqrt(1 - x_der_s_prev ** 2);

const x_der_s = x_der_s_prev + this.stepSize * (ray.bodyMergingObj.fn_p_der_x({ x: x, y: y }) * (1 - x_der_s_prev ** 2) - ray.bodyMergingObj.fn_p_der_y({ x: x, y: y }) * x_der_s_prev * y_der_s_prev) / ray.bodyMergingObj.fn_p({ x: x, y: y });
const y_der_s = y_der_s_prev + this.stepSize * (ray.bodyMergingObj.fn_p_der_y({ x: x, y: y }) * (1 - y_der_s_prev ** 2) - ray.bodyMergingObj.fn_p_der_x({ x: x, y: y }) * x_der_s_prev * y_der_s_prev) / ray.bodyMergingObj.fn_p({ x: x, y: y });
const x_der_s = x_der_s_prev + this.stepSize * (ray.bodyMergingObj.fn_p_der_x({ x: x, y: y, z: ray.wavelength || GREEN_WAVELENGTH }) * (1 - x_der_s_prev ** 2) - ray.bodyMergingObj.fn_p_der_y({ x: x, y: y, z: ray.wavelength || GREEN_WAVELENGTH }) * x_der_s_prev * y_der_s_prev) / ray.bodyMergingObj.fn_p({ x: x, y: y, z: ray.wavelength || GREEN_WAVELENGTH });
const y_der_s = y_der_s_prev + this.stepSize * (ray.bodyMergingObj.fn_p_der_y({ x: x, y: y, z: ray.wavelength || GREEN_WAVELENGTH }) * (1 - y_der_s_prev ** 2) - ray.bodyMergingObj.fn_p_der_x({ x: x, y: y, z: ray.wavelength || GREEN_WAVELENGTH }) * x_der_s_prev * y_der_s_prev) / ray.bodyMergingObj.fn_p({ x: x, y: y, z: ray.wavelength || GREEN_WAVELENGTH });

const x_new = x + this.stepSize * x_der_s;
const y_new = y + this.stepSize * y_der_s;
Expand Down
2 changes: 1 addition & 1 deletion simulator/locales/de.js
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,7 @@ locales["de"] = {
},
"grin_refractive_index": {
"incomplete": true,
"message": "<ul><li>Supported constants:<br><code>pi e</code></li><li>Supported operators:<br><code>+ - * / ^</code></li><li>Supported functions:<br><code>sqrt sin cos tan sec csc cot sinh cosh tanh log arcsin arccos arctan</code></li><li>Only supports differentiable functions.</li><li>The origin of n(x,y) is in the absolute coordinates and does not move with the object. You may double-click a control-point to inspect its absolute coordinates.</li><li>For more accurate simulation, see \"More options...\"</li></ul>"
"message": "<ul><li>Supported constants:<br><code>pi e</code></li><li>Supported operators:<br><code>+ - * / ^</code></li><li>Supported functions:<br><code>sqrt sin cos tan sec csc cot sinh cosh tanh log arcsin arccos arctan</code></li><li>To simulate chromatic dispersion, use parameter <code>lambda</code> for the vacuum wavelength in nanometers.<sup>Beta</sup></li><li>Only supports differentiable functions.</li><li>The origin of n(x,y) is in the absolute coordinates and does not move with the object. You may double-click a control-point to inspect its absolute coordinates.</li><li>For more accurate simulation, see \"More options...\"</li></ul>"
},
"symbolic_grin_note_popover": {
"incomplete": true,
Expand Down
2 changes: 1 addition & 1 deletion simulator/locales/en.js
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ locales["en"] = {
"message": "Symbolic body-merging"
},
"grin_refractive_index": {
"message": "<ul><li>Supported constants:<br><code>pi e</code></li><li>Supported operators:<br><code>+ - * / ^</code></li><li>Supported functions:<br><code>sqrt sin cos tan sec csc cot sinh cosh tanh log arcsin arccos arctan</code></li><li>Only supports differentiable functions.</li><li>The origin of n(x,y) is in the absolute coordinates and does not move with the object. You may double-click a control-point to inspect its absolute coordinates.</li><li>For a more accurate simulation, see \"More options...\"</li></ul>"
"message": "<ul><li>Supported constants:<br><code>pi e</code></li><li>Supported operators:<br><code>+ - * / ^</code></li><li>Supported functions:<br><code>sqrt sin cos tan sec csc cot sinh cosh tanh log arcsin arccos arctan</code></li><li>To simulate chromatic dispersion, use parameter <code>lambda</code> for the vacuum wavelength in nanometers.<sup>Beta</sup></li><li>Only supports differentiable functions.</li><li>The origin of n(x,y) is in the absolute coordinates and does not move with the object. You may double-click a control-point to inspect its absolute coordinates.</li><li>For a more accurate simulation, see \"More options...\"</li></ul>"
},
"symbolic_grin_note_popover": {
"message": "<p>This toggle applies to all GRIN objects in the simulation.</p><p>This simulator has currently two implementations of light propagation between different mediums, for GRIN objects - numerical and symbolic (see 'multRefIndex' and 'devRefIndex' functions in 'CircleGrinGlass.js').</p><p>The numerical implementation is faster but doesn't always work properly (depending on the specific case) in scenarios when used with more than one GRIN object, <b>such that at least one of them has a refractive index function which is not defined in the <u>entire</u> plane</b>, while the symbolic implementation is slower but robust to such problems.</p>"
Expand Down
2 changes: 1 addition & 1 deletion simulator/locales/es.js
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,7 @@ locales["es"] = {
},
"grin_refractive_index": {
"incomplete": true,
"message": "<ul><li>Supported constants:<br><code>pi e</code></li><li>Supported operators:<br><code>+ - * / ^</code></li><li>Supported functions:<br><code>sqrt sin cos tan sec csc cot sinh cosh tanh log arcsin arccos arctan</code></li><li>Sólo soporta funciones diferenciables.</li><li>El origen de n(x,y) está en las coordenadas absolutas y no se mueve con el objeto. Puede hacer doble click sobre un punto de control para inspeccionar sus coordenadas absolutas.</li><li>Para una simulación más precisa, vea \"Más opciones...\"</li></ul>"
"message": "<ul><li>Supported constants:<br><code>pi e</code></li><li>Supported operators:<br><code>+ - * / ^</code></li><li>Supported functions:<br><code>sqrt sin cos tan sec csc cot sinh cosh tanh log arcsin arccos arctan</code></li><li>To simulate chromatic dispersion, use parameter <code>lambda</code> for the vacuum wavelength in nanometers.<sup>Beta</sup></li><li>Sólo soporta funciones diferenciables.</li><li>El origen de n(x,y) está en las coordenadas absolutas y no se mueve con el objeto. Puede hacer doble click sobre un punto de control para inspeccionar sus coordenadas absolutas.</li><li>Para una simulación más precisa, vea \"Más opciones...\"</li></ul>"
},
"symbolic_grin_note_popover": {
"message": "<p>Esta opción se aplica a todos los objetos GRIN de la simulación.</p><p>Actualmente este simulador tiene dos implementaciones de propagación de la luz entre medios, para objetos GRIN - numéricos y simbólicos (vea las funciones 'multRefIndex' y 'devRefIndex' en 'CircleGrinGlass.js').</p><p>La implementación numérica es más rápida pero no siempre funciona correctamente (dependiendo del caso en concreto) en escenarios donde se usa más de un objeto GRIN,<b>tal que al menos una de ellas tiene una función de índice de refracción que no está definida en <u>todo</u> el plano</b>, mientras que la implementación simbólica és más lenta pero robusta con estos problemas.</p>"
Expand Down
2 changes: 1 addition & 1 deletion simulator/locales/fr.js
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,7 @@ locales["fr"] = {
},
"grin_refractive_index": {
"incomplete": true,
"message": "<ul><li>Supported constants:<br><code>pi e</code></li><li>Supported operators:<br><code>+ - * / ^</code></li><li>Supported functions:<br><code>sqrt sin cos tan sec csc cot sinh cosh tanh log arcsin arccos arctan</code></li><li>Only supports differentiable functions.</li><li>The origin of n(x,y) is in the absolute coordinates and does not move with the object. You may double-click a control-point to inspect its absolute coordinates.</li><li>For more accurate simulation, see \"More options...\"</li></ul>"
"message": "<ul><li>Supported constants:<br><code>pi e</code></li><li>Supported operators:<br><code>+ - * / ^</code></li><li>Supported functions:<br><code>sqrt sin cos tan sec csc cot sinh cosh tanh log arcsin arccos arctan</code></li><li>To simulate chromatic dispersion, use parameter <code>lambda</code> for the vacuum wavelength in nanometers.<sup>Beta</sup></li><li>Only supports differentiable functions.</li><li>The origin of n(x,y) is in the absolute coordinates and does not move with the object. You may double-click a control-point to inspect its absolute coordinates.</li><li>For more accurate simulation, see \"More options...\"</li></ul>"
},
"symbolic_grin_note_popover": {
"incomplete": true,
Expand Down
2 changes: 1 addition & 1 deletion simulator/locales/ja.js
Original file line number Diff line number Diff line change
Expand Up @@ -541,7 +541,7 @@ locales["ja"] = {
},
"grin_refractive_index": {
"incomplete": true,
"message": "<ul><li>Supported constants:<br><code>pi e</code></li><li>Supported operators:<br><code>+ - * / ^</code></li><li>Supported functions:<br><code>sqrt sin cos tan sec csc cot sinh cosh tanh log arcsin arccos arctan</code></li><li>Only supports differentiable functions.</li><li>The origin of n(x,y) is in the absolute coordinates and does not move with the object. You may double-click a control-point to inspect its absolute coordinates.</li><li>For more accurate simulation, see \"More options...\"</li></ul>"
"message": "<ul><li>Supported constants:<br><code>pi e</code></li><li>Supported operators:<br><code>+ - * / ^</code></li><li>Supported functions:<br><code>sqrt sin cos tan sec csc cot sinh cosh tanh log arcsin arccos arctan</code></li><li>To simulate chromatic dispersion, use parameter <code>lambda</code> for the vacuum wavelength in nanometers.<sup>Beta</sup></li><li>Only supports differentiable functions.</li><li>The origin of n(x,y) is in the absolute coordinates and does not move with the object. You may double-click a control-point to inspect its absolute coordinates.</li><li>For more accurate simulation, see \"More options...\"</li></ul>"
},
"symbolic_grin_note_popover": {
"incomplete": true,
Expand Down
2 changes: 1 addition & 1 deletion simulator/locales/ko.js
Original file line number Diff line number Diff line change
Expand Up @@ -541,7 +541,7 @@ locales["ko"] = {
},
"grin_refractive_index": {
"incomplete": true,
"message": "<ul><li>Supported constants:<br><code>pi e</code></li><li>Supported operators:<br><code>+ - * / ^</code></li><li>Supported functions:<br><code>sqrt sin cos tan sec csc cot sinh cosh tanh log arcsin arccos arctan</code></li><li>Only supports differentiable functions.</li><li>The origin of n(x,y) is in the absolute coordinates and does not move with the object. You may double-click a control-point to inspect its absolute coordinates.</li><li>For more accurate simulation, see \"More options...\"</li></ul>"
"message": "<ul><li>Supported constants:<br><code>pi e</code></li><li>Supported operators:<br><code>+ - * / ^</code></li><li>Supported functions:<br><code>sqrt sin cos tan sec csc cot sinh cosh tanh log arcsin arccos arctan</code></li><li>To simulate chromatic dispersion, use parameter <code>lambda</code> for the vacuum wavelength in nanometers.<sup>Beta</sup></li><li>Only supports differentiable functions.</li><li>The origin of n(x,y) is in the absolute coordinates and does not move with the object. You may double-click a control-point to inspect its absolute coordinates.</li><li>For more accurate simulation, see \"More options...\"</li></ul>"
},
"symbolic_grin_note_popover": {
"incomplete": true,
Expand Down
2 changes: 1 addition & 1 deletion simulator/locales/nl.js
Original file line number Diff line number Diff line change
Expand Up @@ -481,7 +481,7 @@ locales["nl"] = {
},
"grin_refractive_index": {
"incomplete": true,
"message": "<ul><li>Supported constants:<br><code>pi e</code></li><li>Supported operators:<br><code>+ - * / ^</code></li><li>Supported functions:<br><code>sqrt sin cos tan sec csc cot sinh cosh tanh log arcsin arccos arctan</code></li><li>Only supports differentiable functions.</li><li>The origin of n(x,y) is in the absolute coordinates and does not move with the object. You may double-click a control-point to inspect its absolute coordinates.</li><li>For more accurate simulation, see \"More options...\"</li></ul>"
"message": "<ul><li>Supported constants:<br><code>pi e</code></li><li>Supported operators:<br><code>+ - * / ^</code></li><li>Supported functions:<br><code>sqrt sin cos tan sec csc cot sinh cosh tanh log arcsin arccos arctan</code></li><li>To simulate chromatic dispersion, use parameter <code>lambda</code> for the vacuum wavelength in nanometers.<sup>Beta</sup></li><li>Only supports differentiable functions.</li><li>The origin of n(x,y) is in the absolute coordinates and does not move with the object. You may double-click a control-point to inspect its absolute coordinates.</li><li>For more accurate simulation, see \"More options...\"</li></ul>"
},
"symbolic_grin_note_popover": {
"incomplete": true,
Expand Down
2 changes: 1 addition & 1 deletion simulator/locales/pl.js
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,7 @@ locales["pl"] = {
},
"grin_refractive_index": {
"incomplete": true,
"message": "<ul><li>Supported constants:<br><code>pi e</code></li><li>Supported operators:<br><code>+ - * / ^</code></li><li>Supported functions:<br><code>sqrt sin cos tan sec csc cot sinh cosh tanh log arcsin arccos arctan</code></li><li>Obsługuje tylko funkcje różniczkowalne.</li><li>Początek n(x,y) jest we współrzędnych bezwzględnych i nie porusza się wraz z obiektem. Możesz kliknąć dwukrotnie punkt kontrolny, aby sprawdzić jego współrzędne bezwzględne.</li><li>Aby uzyskać dokładniejszą symulację, zobacz \"Więcej opcji...\"</li></ul>"
"message": "<ul><li>Supported constants:<br><code>pi e</code></li><li>Supported operators:<br><code>+ - * / ^</code></li><li>Supported functions:<br><code>sqrt sin cos tan sec csc cot sinh cosh tanh log arcsin arccos arctan</code></li><li>To simulate chromatic dispersion, use parameter <code>lambda</code> for the vacuum wavelength in nanometers.<sup>Beta</sup></li><li>Obsługuje tylko funkcje różniczkowalne.</li><li>Początek n(x,y) jest we współrzędnych bezwzględnych i nie porusza się wraz z obiektem. Możesz kliknąć dwukrotnie punkt kontrolny, aby sprawdzić jego współrzędne bezwzględne.</li><li>Aby uzyskać dokładniejszą symulację, zobacz \"Więcej opcji...\"</li></ul>"
},
"symbolic_grin_note_popover": {
"message": "<p>Ten przełącznik dotyczy wszystkich obiektów GRIN w symulacji.</p><p>Ten symulator ma obecnie dwie implementacje propagacji światła między różnymi ośrodkami dla obiektów GRIN - numeryczną i symboliczną (patrz funkcje 'multRefIndex' i 'devRefIndex' w 'CircleGrinGlass.js').</p><p>Implementacja numeryczna jest szybsza, ale nie zawsze działa poprawnie (w zależności od konkretnego przypadku) w scenariuszach, gdy jest używana z więcej niż jednym obiektem GRIN, <b>takim, że przynajmniej jeden z nich ma funkcję współczynnika załamania światła, która nie jest zdefiniowana w <u>całej</u> płaszczyźnie</b>, podczas gdy implementacja symboliczna jest wolniejsza, ale odporna na takie problemy.</p>"
Expand Down
2 changes: 1 addition & 1 deletion simulator/locales/pt_BR.js
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,7 @@ locales["pt-BR"] = {
"message": "União simbólica de corpos"
},
"grin_refractive_index": {
"message": "<ul><li>Constantes suportadas:<br><code>pi e</code></li><li>Operadores suportados:<br><code>+ - * / ^</code></li><li>Funções suportadas:<br><code>sqrt sin cos tan sec csc cot sinh cosh tanh log arcsin arccos arctan</code></li><li>Somente suporta funções diferenciáveis.</li><li>A origem de n(x,y) está em coordenadas absolutas e n~~ao move com o objeto. Você pode clicar duas vezes em um ponto de controle para inspecionar suas coordenadas absolutas.</li><li>Para simulação mais precisa, veja \"Mais opções...\"</li></ul>"
"message": "<ul><li>Constantes suportadas:<br><code>pi e</code></li><li>Operadores suportados:<br><code>+ - * / ^</code></li><li>Funções suportadas:<br><code>sqrt sin cos tan sec csc cot sinh cosh tanh log arcsin arccos arctan</code></li><li>To simulate chromatic dispersion, use parameter <code>lambda</code> for the vacuum wavelength in nanometers.<sup>Beta</sup></li><li>Somente suporta funções diferenciáveis.</li><li>A origem de n(x,y) está em coordenadas absolutas e n~~ao move com o objeto. Você pode clicar duas vezes em um ponto de controle para inspecionar suas coordenadas absolutas.</li><li>Para simulação mais precisa, veja \"Mais opções...\"</li></ul>"
},
"symbolic_grin_note_popover": {
"message": "<p>Esta opção se aplica a todos objetos GRIN na simulação.</p><p>Este simulador atualmente possi duas implementações de propagação de luz entre meios diferentes, para objetos GRIN - numérica e simbólica (ver funções 'multRefIndex' e 'devRefIndex' em 'CircleGrinGlass.js').</p><p>A implementação numérica é mais rápida mas nem sempre funciona corretamente (dependende do caso específico) em cenários quando é usada com mais de um objeto GRIN, <b>tal que ao menos um deles possua uma função de índice refrativo que não é definida <u>todo</u> o plano</b>, enquanto a implementação simbólica é mais lenta, mas robusta a esse tipo de problema.</p>"
Expand Down
2 changes: 1 addition & 1 deletion simulator/locales/ru.js
Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,7 @@ locales["ru"] = {
},
"grin_refractive_index": {
"incomplete": true,
"message": "<ul><li>Supported constants:<br><code>pi e</code></li><li>Supported operators:<br><code>+ - * / ^</code></li><li>Supported functions:<br><code>sqrt sin cos tan sec csc cot sinh cosh tanh log arcsin arccos arctan</code></li><li>Only supports differentiable functions.</li><li>The origin of n(x,y) is in the absolute coordinates and does not move with the object. You may double-click a control-point to inspect its absolute coordinates.</li><li>For more accurate simulation, see \"More options...\"</li></ul>"
"message": "<ul><li>Supported constants:<br><code>pi e</code></li><li>Supported operators:<br><code>+ - * / ^</code></li><li>Supported functions:<br><code>sqrt sin cos tan sec csc cot sinh cosh tanh log arcsin arccos arctan</code></li><li>To simulate chromatic dispersion, use parameter <code>lambda</code> for the vacuum wavelength in nanometers.<sup>Beta</sup></li><li>Only supports differentiable functions.</li><li>The origin of n(x,y) is in the absolute coordinates and does not move with the object. You may double-click a control-point to inspect its absolute coordinates.</li><li>For more accurate simulation, see \"More options...\"</li></ul>"
},
"symbolic_grin_note_popover": {
"incomplete": true,
Expand Down
Loading

0 comments on commit c43507c

Please sign in to comment.