Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: non-uniform beam intensity #26

Open
joedf opened this issue Apr 23, 2023 · 1 comment
Open

Feature: non-uniform beam intensity #26

joedf opened this issue Apr 23, 2023 · 1 comment
Labels
enhancement New feature or request

Comments

@joedf
Copy link
Owner

joedf commented Apr 23, 2023

Demo/test using a Gaussian point spread function like beam:
https://codepen.io/joedf/pen/jOeyKZg?editors=0111

@joedf joedf added the enhancement New feature or request label Apr 23, 2023
@joedf
Copy link
Owner Author

joedf commented Dec 4, 2024

// gaussian where the curve is defined by a=1,b=0,c=0.3
// to get a bell curve that is going from 1 to 0 in y, centered on 0 in x.
// https://www.desmos.com/calculator/pbnihoalbr
// sampled at 10 spots: 0 to 1 at 0.1 increments
// Approximation (by hand):
// (0,1), (.1,.95), (.2,.8), (.4,.4), (.5,.25),
// (.6,.135), (.7,.06), (.8,.03), (.9,.01), (1,0)
var gaussianStops = [0,gg(1), 0.1,gg(.95), .2,gg(.8), .4,gg(.4), .5,gg(.25),
                    .6,gg(.135), .7,gg(.06), .8,gg(.03), .9,gg(.01), 1,gg(0)];

// calculate it with a function instead!
// basic gaussian curve: g = a exp(- (x-b)^2 / (2c^2))
// https://en.wikipedia.org/wiki/Gaussian_function
// make a function that calculates gradient stops
// where r is the sampling rate (along the x-axis)
// returns r+1 stops (because with count the 0,1 point)
function gaussianGradient(a,b,c,r=10,useAlpha=false) {
  var stops = [];
  for(var i=0; i<=r; i++){
    const x = i / r;
    const g = a * Math.exp( (-Math.pow(x-b,2)) / (2*Math.pow(c,2)) );
    stops.push(x, scaledIntensityRGBA(g, useAlpha));
  }
  return stops;
}

// replace with a calculated/more accurate one
gaussianStops = gaussianGradient(1,0,0.3,1000,1);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant