Gaussian along an ellipse

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
1
down vote

favorite












Best way to describe what I mean is with an example; I know how to generate a "Gaussian along a line":



$$e^-h_2^2((x-h_5)cos(h_3)+(y-h_6)sin(h_3)).^2$$



Some example matlab code:



h1 = 0.025;
h2 = 0.5;
h3 = pi/16;
h4 = pi/2.25;
h5 = 50;
h6 = 60;

[y,x] = ndgrid(1:120,1:120);

figure;
imshow(exp(-h2^2*((x-h5).*cos(h3)+(y-h6).*sin(h3)).^2),)


enter image description here



This is a "Gaussian along a line". How would I go about doing the same thing, but for an ellipse instead? Preferably where the function is equal to 1 along the ellipse boundary like it is for this equation of the line:



$$(x-h_5)cos(h_3)+(y-h_6)sin(h_3)$$



and also has a parameter like $h_2$ where I can control the spread (i.e. variance).



EDIT:



When using:



h = 30;
k = 40;
a = 5;
b = 6;
h2 = 4;

figure;
imshow(exp(-h2^2*( (x-h).^2/a^2 + (y-k).^2/b^2 - 1).^2),)


h = 30;
k = 40;
a = 25;
b = 30;
h2 = 4;

figure;
imshow(exp(-h2^2*( (x-h).^2/a^2 + (y-k).^2/b^2 - 1).^2),)


Even though $h_2$ is the same the variance seems to increase:



enter image description here







share|cite|improve this question

























    up vote
    1
    down vote

    favorite












    Best way to describe what I mean is with an example; I know how to generate a "Gaussian along a line":



    $$e^-h_2^2((x-h_5)cos(h_3)+(y-h_6)sin(h_3)).^2$$



    Some example matlab code:



    h1 = 0.025;
    h2 = 0.5;
    h3 = pi/16;
    h4 = pi/2.25;
    h5 = 50;
    h6 = 60;

    [y,x] = ndgrid(1:120,1:120);

    figure;
    imshow(exp(-h2^2*((x-h5).*cos(h3)+(y-h6).*sin(h3)).^2),)


    enter image description here



    This is a "Gaussian along a line". How would I go about doing the same thing, but for an ellipse instead? Preferably where the function is equal to 1 along the ellipse boundary like it is for this equation of the line:



    $$(x-h_5)cos(h_3)+(y-h_6)sin(h_3)$$



    and also has a parameter like $h_2$ where I can control the spread (i.e. variance).



    EDIT:



    When using:



    h = 30;
    k = 40;
    a = 5;
    b = 6;
    h2 = 4;

    figure;
    imshow(exp(-h2^2*( (x-h).^2/a^2 + (y-k).^2/b^2 - 1).^2),)


    h = 30;
    k = 40;
    a = 25;
    b = 30;
    h2 = 4;

    figure;
    imshow(exp(-h2^2*( (x-h).^2/a^2 + (y-k).^2/b^2 - 1).^2),)


    Even though $h_2$ is the same the variance seems to increase:



    enter image description here







    share|cite|improve this question























      up vote
      1
      down vote

      favorite









      up vote
      1
      down vote

      favorite











      Best way to describe what I mean is with an example; I know how to generate a "Gaussian along a line":



      $$e^-h_2^2((x-h_5)cos(h_3)+(y-h_6)sin(h_3)).^2$$



      Some example matlab code:



      h1 = 0.025;
      h2 = 0.5;
      h3 = pi/16;
      h4 = pi/2.25;
      h5 = 50;
      h6 = 60;

      [y,x] = ndgrid(1:120,1:120);

      figure;
      imshow(exp(-h2^2*((x-h5).*cos(h3)+(y-h6).*sin(h3)).^2),)


      enter image description here



      This is a "Gaussian along a line". How would I go about doing the same thing, but for an ellipse instead? Preferably where the function is equal to 1 along the ellipse boundary like it is for this equation of the line:



      $$(x-h_5)cos(h_3)+(y-h_6)sin(h_3)$$



      and also has a parameter like $h_2$ where I can control the spread (i.e. variance).



      EDIT:



      When using:



      h = 30;
      k = 40;
      a = 5;
      b = 6;
      h2 = 4;

      figure;
      imshow(exp(-h2^2*( (x-h).^2/a^2 + (y-k).^2/b^2 - 1).^2),)


      h = 30;
      k = 40;
      a = 25;
      b = 30;
      h2 = 4;

      figure;
      imshow(exp(-h2^2*( (x-h).^2/a^2 + (y-k).^2/b^2 - 1).^2),)


      Even though $h_2$ is the same the variance seems to increase:



      enter image description here







      share|cite|improve this question













      Best way to describe what I mean is with an example; I know how to generate a "Gaussian along a line":



      $$e^-h_2^2((x-h_5)cos(h_3)+(y-h_6)sin(h_3)).^2$$



      Some example matlab code:



      h1 = 0.025;
      h2 = 0.5;
      h3 = pi/16;
      h4 = pi/2.25;
      h5 = 50;
      h6 = 60;

      [y,x] = ndgrid(1:120,1:120);

      figure;
      imshow(exp(-h2^2*((x-h5).*cos(h3)+(y-h6).*sin(h3)).^2),)


      enter image description here



      This is a "Gaussian along a line". How would I go about doing the same thing, but for an ellipse instead? Preferably where the function is equal to 1 along the ellipse boundary like it is for this equation of the line:



      $$(x-h_5)cos(h_3)+(y-h_6)sin(h_3)$$



      and also has a parameter like $h_2$ where I can control the spread (i.e. variance).



      EDIT:



      When using:



      h = 30;
      k = 40;
      a = 5;
      b = 6;
      h2 = 4;

      figure;
      imshow(exp(-h2^2*( (x-h).^2/a^2 + (y-k).^2/b^2 - 1).^2),)


      h = 30;
      k = 40;
      a = 25;
      b = 30;
      h2 = 4;

      figure;
      imshow(exp(-h2^2*( (x-h).^2/a^2 + (y-k).^2/b^2 - 1).^2),)


      Even though $h_2$ is the same the variance seems to increase:



      enter image description here









      share|cite|improve this question












      share|cite|improve this question




      share|cite|improve this question








      edited Jul 30 at 1:10









      Michael Hardy

      204k23186461




      204k23186461









      asked Jul 26 at 15:41









      Justin

      1351112




      1351112




















          2 Answers
          2






          active

          oldest

          votes

















          up vote
          1
          down vote













          The trick is to build a function that cancels along the curve and is nonzero elsewhere.



          In the case of a line,



          $$f(x,y)=ax+by+c$$ is a perfect candidate.



          For an axis aligned, centered ellipse,



          $$f(x,y)=fracx^2a^2+fracy^2b^2-1.$$



          In both cases, the Gaussian takes the form



          $$e^-h^2f^2(x,y)$$ giving, for the ellipse



          $$e^-h^2left(fracx^2a^2+fracy^2b^2-1right)^2.$$






          share|cite|improve this answer





















          • The problem isn't precisely specified, but maybe you want $f$ to be linear to first order? eg for fixed $y$, your gaussian looks like $A exp (-B(x^2 - C)^2)$
            – Calvin Khor
            Jul 26 at 16:07











          • The variance seems to scale with $a$ and $b$. i.e. the white area is "thicker" when the major and minor axes are increased. Is there a way to make it constant even if these parameters are modified?
            – Justin
            Jul 26 at 16:09










          • Can you check my edits to see what I mean?
            – Justin
            Jul 26 at 16:12










          • @Justin: yep, you must adjust $h$, and this simple approach won't ensure a constant thickness.
            – Yves Daoust
            Jul 26 at 16:27










          • @YvesDaoust Any tips for how I can ensure constant thickness?
            – Justin
            Jul 26 at 16:34

















          up vote
          1
          down vote













          One thing you can try is the following- let $C=C(s)$ be a curve defined for $sin I$, so maybe a line, or a curve like $y=x^2$ or an ellipse. Then define for $mathbf x = (x,y)$,



          $$ f_C(mathbf x) = e^mathbf x - C(s)$$



          The quantity $inf_sin I |mathbf x - C(s)|$ is the shortest distance to the curve $C$.



          In the case $C$ is a line, this should be the same as yours after some redefining of constants, as the shortest distance to a line is obtained by dropping a perpendicular, and hence you will see the intensity die out as you move out perpendicularly from the line, with the exponential decay matching the 1D Gaussian with variance $sigma^2$.



          The function $g(s) := |mathbf x - C(s)|^2$ is differentiable if $C$ is, with derivative



          $$g'(s) = 2(mathbf x - C(s))cdot C'(s)$$
          so the infimum is at a point $C_* = C(s_*)$ where the tangent of the curve is perpendicular to the line joining $mathbf x$ and $C_*$, or in other words, $mathbf x-C_*$ needs to be parallel to the normal vector of the curve. This is a nice picture, but I don't know how it translates into code.



          In the case of an ellipse, say of the form



          $$C(s) = (a cos s, b sin s), s in [0,2π)$$
          Then $C'(s) = (-a sin s, bcos s)$, and the equation to solve is



          $$0 = (mathbf x - C(s))cdot C'(s) = -a(x-acos s)sin s + b(y-bsin s)cos s$$



          I don't see this having an easy-to-write-down solution. You'll also need to check that the second derivative is positive, and then choose the smallest value of $g(s)$ out of all the minimum points.



          On a quick google, I found the following document https://www.geometrictools.com/Documentation/DistancePointEllipseEllipsoid.pdf which seems to go into detail for computing such closest points on an ellipse.



          In the case of a circle of radius $R$, its not so hard. Recenter so that the circle $C$ is entered at the origin, and write $mathbf x = r mathbf u$ where $mathbf u $ is a unit vector, and $r=r(mathbf x) = |mathbf x|$ is the distance of $mathbf x$ to 0. Then



          $$f_C(mathbf x) = e^^2 / 2sigma^2$$



          For an arbitrarily located circle $ = R$, you just need to use $r(mathbf x) = |mathbf x - mathbf x_0|$ instead. If $mathbf x_0 = (x_0,y_0)$, then we arrive at



          $$f_C(x,y) = expleft(frac-left2sigma^2 right)$$



          Naively substituting the circle formula $|mathbf x - mathbf x_0| = R$ with the similar formula for the ellipse $|mathbf x - mathbf x_0| + |mathbf x - mathbf x_1| = R$ ,
          $$f_C(mathbf x) = expleft(frac^22sigma^2right) ?$$



          smallmediumlarge



          gives you something that looks reasonable, but you can see that the level sets are not perfect. Regardless, the spread of the variance doesn't depend on how big the ellipse is.






          share|cite|improve this answer























            Your Answer




            StackExchange.ifUsing("editor", function ()
            return StackExchange.using("mathjaxEditing", function ()
            StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix)
            StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["$", "$"], ["\\(","\\)"]]);
            );
            );
            , "mathjax-editing");

            StackExchange.ready(function()
            var channelOptions =
            tags: "".split(" "),
            id: "69"
            ;
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function()
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled)
            StackExchange.using("snippets", function()
            createEditor();
            );

            else
            createEditor();

            );

            function createEditor()
            StackExchange.prepareEditor(
            heartbeatType: 'answer',
            convertImagesToLinks: true,
            noModals: false,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            noCode: true, onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            );



            );








             

            draft saved


            draft discarded


















            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmath.stackexchange.com%2fquestions%2f2863523%2fgaussian-along-an-ellipse%23new-answer', 'question_page');

            );

            Post as a guest






























            2 Answers
            2






            active

            oldest

            votes








            2 Answers
            2






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes








            up vote
            1
            down vote













            The trick is to build a function that cancels along the curve and is nonzero elsewhere.



            In the case of a line,



            $$f(x,y)=ax+by+c$$ is a perfect candidate.



            For an axis aligned, centered ellipse,



            $$f(x,y)=fracx^2a^2+fracy^2b^2-1.$$



            In both cases, the Gaussian takes the form



            $$e^-h^2f^2(x,y)$$ giving, for the ellipse



            $$e^-h^2left(fracx^2a^2+fracy^2b^2-1right)^2.$$






            share|cite|improve this answer





















            • The problem isn't precisely specified, but maybe you want $f$ to be linear to first order? eg for fixed $y$, your gaussian looks like $A exp (-B(x^2 - C)^2)$
              – Calvin Khor
              Jul 26 at 16:07











            • The variance seems to scale with $a$ and $b$. i.e. the white area is "thicker" when the major and minor axes are increased. Is there a way to make it constant even if these parameters are modified?
              – Justin
              Jul 26 at 16:09










            • Can you check my edits to see what I mean?
              – Justin
              Jul 26 at 16:12










            • @Justin: yep, you must adjust $h$, and this simple approach won't ensure a constant thickness.
              – Yves Daoust
              Jul 26 at 16:27










            • @YvesDaoust Any tips for how I can ensure constant thickness?
              – Justin
              Jul 26 at 16:34














            up vote
            1
            down vote













            The trick is to build a function that cancels along the curve and is nonzero elsewhere.



            In the case of a line,



            $$f(x,y)=ax+by+c$$ is a perfect candidate.



            For an axis aligned, centered ellipse,



            $$f(x,y)=fracx^2a^2+fracy^2b^2-1.$$



            In both cases, the Gaussian takes the form



            $$e^-h^2f^2(x,y)$$ giving, for the ellipse



            $$e^-h^2left(fracx^2a^2+fracy^2b^2-1right)^2.$$






            share|cite|improve this answer





















            • The problem isn't precisely specified, but maybe you want $f$ to be linear to first order? eg for fixed $y$, your gaussian looks like $A exp (-B(x^2 - C)^2)$
              – Calvin Khor
              Jul 26 at 16:07











            • The variance seems to scale with $a$ and $b$. i.e. the white area is "thicker" when the major and minor axes are increased. Is there a way to make it constant even if these parameters are modified?
              – Justin
              Jul 26 at 16:09










            • Can you check my edits to see what I mean?
              – Justin
              Jul 26 at 16:12










            • @Justin: yep, you must adjust $h$, and this simple approach won't ensure a constant thickness.
              – Yves Daoust
              Jul 26 at 16:27










            • @YvesDaoust Any tips for how I can ensure constant thickness?
              – Justin
              Jul 26 at 16:34












            up vote
            1
            down vote










            up vote
            1
            down vote









            The trick is to build a function that cancels along the curve and is nonzero elsewhere.



            In the case of a line,



            $$f(x,y)=ax+by+c$$ is a perfect candidate.



            For an axis aligned, centered ellipse,



            $$f(x,y)=fracx^2a^2+fracy^2b^2-1.$$



            In both cases, the Gaussian takes the form



            $$e^-h^2f^2(x,y)$$ giving, for the ellipse



            $$e^-h^2left(fracx^2a^2+fracy^2b^2-1right)^2.$$






            share|cite|improve this answer













            The trick is to build a function that cancels along the curve and is nonzero elsewhere.



            In the case of a line,



            $$f(x,y)=ax+by+c$$ is a perfect candidate.



            For an axis aligned, centered ellipse,



            $$f(x,y)=fracx^2a^2+fracy^2b^2-1.$$



            In both cases, the Gaussian takes the form



            $$e^-h^2f^2(x,y)$$ giving, for the ellipse



            $$e^-h^2left(fracx^2a^2+fracy^2b^2-1right)^2.$$







            share|cite|improve this answer













            share|cite|improve this answer



            share|cite|improve this answer











            answered Jul 26 at 15:55









            Yves Daoust

            110k665203




            110k665203











            • The problem isn't precisely specified, but maybe you want $f$ to be linear to first order? eg for fixed $y$, your gaussian looks like $A exp (-B(x^2 - C)^2)$
              – Calvin Khor
              Jul 26 at 16:07











            • The variance seems to scale with $a$ and $b$. i.e. the white area is "thicker" when the major and minor axes are increased. Is there a way to make it constant even if these parameters are modified?
              – Justin
              Jul 26 at 16:09










            • Can you check my edits to see what I mean?
              – Justin
              Jul 26 at 16:12










            • @Justin: yep, you must adjust $h$, and this simple approach won't ensure a constant thickness.
              – Yves Daoust
              Jul 26 at 16:27










            • @YvesDaoust Any tips for how I can ensure constant thickness?
              – Justin
              Jul 26 at 16:34
















            • The problem isn't precisely specified, but maybe you want $f$ to be linear to first order? eg for fixed $y$, your gaussian looks like $A exp (-B(x^2 - C)^2)$
              – Calvin Khor
              Jul 26 at 16:07











            • The variance seems to scale with $a$ and $b$. i.e. the white area is "thicker" when the major and minor axes are increased. Is there a way to make it constant even if these parameters are modified?
              – Justin
              Jul 26 at 16:09










            • Can you check my edits to see what I mean?
              – Justin
              Jul 26 at 16:12










            • @Justin: yep, you must adjust $h$, and this simple approach won't ensure a constant thickness.
              – Yves Daoust
              Jul 26 at 16:27










            • @YvesDaoust Any tips for how I can ensure constant thickness?
              – Justin
              Jul 26 at 16:34















            The problem isn't precisely specified, but maybe you want $f$ to be linear to first order? eg for fixed $y$, your gaussian looks like $A exp (-B(x^2 - C)^2)$
            – Calvin Khor
            Jul 26 at 16:07





            The problem isn't precisely specified, but maybe you want $f$ to be linear to first order? eg for fixed $y$, your gaussian looks like $A exp (-B(x^2 - C)^2)$
            – Calvin Khor
            Jul 26 at 16:07













            The variance seems to scale with $a$ and $b$. i.e. the white area is "thicker" when the major and minor axes are increased. Is there a way to make it constant even if these parameters are modified?
            – Justin
            Jul 26 at 16:09




            The variance seems to scale with $a$ and $b$. i.e. the white area is "thicker" when the major and minor axes are increased. Is there a way to make it constant even if these parameters are modified?
            – Justin
            Jul 26 at 16:09












            Can you check my edits to see what I mean?
            – Justin
            Jul 26 at 16:12




            Can you check my edits to see what I mean?
            – Justin
            Jul 26 at 16:12












            @Justin: yep, you must adjust $h$, and this simple approach won't ensure a constant thickness.
            – Yves Daoust
            Jul 26 at 16:27




            @Justin: yep, you must adjust $h$, and this simple approach won't ensure a constant thickness.
            – Yves Daoust
            Jul 26 at 16:27












            @YvesDaoust Any tips for how I can ensure constant thickness?
            – Justin
            Jul 26 at 16:34




            @YvesDaoust Any tips for how I can ensure constant thickness?
            – Justin
            Jul 26 at 16:34










            up vote
            1
            down vote













            One thing you can try is the following- let $C=C(s)$ be a curve defined for $sin I$, so maybe a line, or a curve like $y=x^2$ or an ellipse. Then define for $mathbf x = (x,y)$,



            $$ f_C(mathbf x) = e^mathbf x - C(s)$$



            The quantity $inf_sin I |mathbf x - C(s)|$ is the shortest distance to the curve $C$.



            In the case $C$ is a line, this should be the same as yours after some redefining of constants, as the shortest distance to a line is obtained by dropping a perpendicular, and hence you will see the intensity die out as you move out perpendicularly from the line, with the exponential decay matching the 1D Gaussian with variance $sigma^2$.



            The function $g(s) := |mathbf x - C(s)|^2$ is differentiable if $C$ is, with derivative



            $$g'(s) = 2(mathbf x - C(s))cdot C'(s)$$
            so the infimum is at a point $C_* = C(s_*)$ where the tangent of the curve is perpendicular to the line joining $mathbf x$ and $C_*$, or in other words, $mathbf x-C_*$ needs to be parallel to the normal vector of the curve. This is a nice picture, but I don't know how it translates into code.



            In the case of an ellipse, say of the form



            $$C(s) = (a cos s, b sin s), s in [0,2π)$$
            Then $C'(s) = (-a sin s, bcos s)$, and the equation to solve is



            $$0 = (mathbf x - C(s))cdot C'(s) = -a(x-acos s)sin s + b(y-bsin s)cos s$$



            I don't see this having an easy-to-write-down solution. You'll also need to check that the second derivative is positive, and then choose the smallest value of $g(s)$ out of all the minimum points.



            On a quick google, I found the following document https://www.geometrictools.com/Documentation/DistancePointEllipseEllipsoid.pdf which seems to go into detail for computing such closest points on an ellipse.



            In the case of a circle of radius $R$, its not so hard. Recenter so that the circle $C$ is entered at the origin, and write $mathbf x = r mathbf u$ where $mathbf u $ is a unit vector, and $r=r(mathbf x) = |mathbf x|$ is the distance of $mathbf x$ to 0. Then



            $$f_C(mathbf x) = e^^2 / 2sigma^2$$



            For an arbitrarily located circle $ = R$, you just need to use $r(mathbf x) = |mathbf x - mathbf x_0|$ instead. If $mathbf x_0 = (x_0,y_0)$, then we arrive at



            $$f_C(x,y) = expleft(frac-left2sigma^2 right)$$



            Naively substituting the circle formula $|mathbf x - mathbf x_0| = R$ with the similar formula for the ellipse $|mathbf x - mathbf x_0| + |mathbf x - mathbf x_1| = R$ ,
            $$f_C(mathbf x) = expleft(frac^22sigma^2right) ?$$



            smallmediumlarge



            gives you something that looks reasonable, but you can see that the level sets are not perfect. Regardless, the spread of the variance doesn't depend on how big the ellipse is.






            share|cite|improve this answer



























              up vote
              1
              down vote













              One thing you can try is the following- let $C=C(s)$ be a curve defined for $sin I$, so maybe a line, or a curve like $y=x^2$ or an ellipse. Then define for $mathbf x = (x,y)$,



              $$ f_C(mathbf x) = e^mathbf x - C(s)$$



              The quantity $inf_sin I |mathbf x - C(s)|$ is the shortest distance to the curve $C$.



              In the case $C$ is a line, this should be the same as yours after some redefining of constants, as the shortest distance to a line is obtained by dropping a perpendicular, and hence you will see the intensity die out as you move out perpendicularly from the line, with the exponential decay matching the 1D Gaussian with variance $sigma^2$.



              The function $g(s) := |mathbf x - C(s)|^2$ is differentiable if $C$ is, with derivative



              $$g'(s) = 2(mathbf x - C(s))cdot C'(s)$$
              so the infimum is at a point $C_* = C(s_*)$ where the tangent of the curve is perpendicular to the line joining $mathbf x$ and $C_*$, or in other words, $mathbf x-C_*$ needs to be parallel to the normal vector of the curve. This is a nice picture, but I don't know how it translates into code.



              In the case of an ellipse, say of the form



              $$C(s) = (a cos s, b sin s), s in [0,2π)$$
              Then $C'(s) = (-a sin s, bcos s)$, and the equation to solve is



              $$0 = (mathbf x - C(s))cdot C'(s) = -a(x-acos s)sin s + b(y-bsin s)cos s$$



              I don't see this having an easy-to-write-down solution. You'll also need to check that the second derivative is positive, and then choose the smallest value of $g(s)$ out of all the minimum points.



              On a quick google, I found the following document https://www.geometrictools.com/Documentation/DistancePointEllipseEllipsoid.pdf which seems to go into detail for computing such closest points on an ellipse.



              In the case of a circle of radius $R$, its not so hard. Recenter so that the circle $C$ is entered at the origin, and write $mathbf x = r mathbf u$ where $mathbf u $ is a unit vector, and $r=r(mathbf x) = |mathbf x|$ is the distance of $mathbf x$ to 0. Then



              $$f_C(mathbf x) = e^^2 / 2sigma^2$$



              For an arbitrarily located circle $ = R$, you just need to use $r(mathbf x) = |mathbf x - mathbf x_0|$ instead. If $mathbf x_0 = (x_0,y_0)$, then we arrive at



              $$f_C(x,y) = expleft(frac-left2sigma^2 right)$$



              Naively substituting the circle formula $|mathbf x - mathbf x_0| = R$ with the similar formula for the ellipse $|mathbf x - mathbf x_0| + |mathbf x - mathbf x_1| = R$ ,
              $$f_C(mathbf x) = expleft(frac^22sigma^2right) ?$$



              smallmediumlarge



              gives you something that looks reasonable, but you can see that the level sets are not perfect. Regardless, the spread of the variance doesn't depend on how big the ellipse is.






              share|cite|improve this answer

























                up vote
                1
                down vote










                up vote
                1
                down vote









                One thing you can try is the following- let $C=C(s)$ be a curve defined for $sin I$, so maybe a line, or a curve like $y=x^2$ or an ellipse. Then define for $mathbf x = (x,y)$,



                $$ f_C(mathbf x) = e^mathbf x - C(s)$$



                The quantity $inf_sin I |mathbf x - C(s)|$ is the shortest distance to the curve $C$.



                In the case $C$ is a line, this should be the same as yours after some redefining of constants, as the shortest distance to a line is obtained by dropping a perpendicular, and hence you will see the intensity die out as you move out perpendicularly from the line, with the exponential decay matching the 1D Gaussian with variance $sigma^2$.



                The function $g(s) := |mathbf x - C(s)|^2$ is differentiable if $C$ is, with derivative



                $$g'(s) = 2(mathbf x - C(s))cdot C'(s)$$
                so the infimum is at a point $C_* = C(s_*)$ where the tangent of the curve is perpendicular to the line joining $mathbf x$ and $C_*$, or in other words, $mathbf x-C_*$ needs to be parallel to the normal vector of the curve. This is a nice picture, but I don't know how it translates into code.



                In the case of an ellipse, say of the form



                $$C(s) = (a cos s, b sin s), s in [0,2π)$$
                Then $C'(s) = (-a sin s, bcos s)$, and the equation to solve is



                $$0 = (mathbf x - C(s))cdot C'(s) = -a(x-acos s)sin s + b(y-bsin s)cos s$$



                I don't see this having an easy-to-write-down solution. You'll also need to check that the second derivative is positive, and then choose the smallest value of $g(s)$ out of all the minimum points.



                On a quick google, I found the following document https://www.geometrictools.com/Documentation/DistancePointEllipseEllipsoid.pdf which seems to go into detail for computing such closest points on an ellipse.



                In the case of a circle of radius $R$, its not so hard. Recenter so that the circle $C$ is entered at the origin, and write $mathbf x = r mathbf u$ where $mathbf u $ is a unit vector, and $r=r(mathbf x) = |mathbf x|$ is the distance of $mathbf x$ to 0. Then



                $$f_C(mathbf x) = e^^2 / 2sigma^2$$



                For an arbitrarily located circle $ = R$, you just need to use $r(mathbf x) = |mathbf x - mathbf x_0|$ instead. If $mathbf x_0 = (x_0,y_0)$, then we arrive at



                $$f_C(x,y) = expleft(frac-left2sigma^2 right)$$



                Naively substituting the circle formula $|mathbf x - mathbf x_0| = R$ with the similar formula for the ellipse $|mathbf x - mathbf x_0| + |mathbf x - mathbf x_1| = R$ ,
                $$f_C(mathbf x) = expleft(frac^22sigma^2right) ?$$



                smallmediumlarge



                gives you something that looks reasonable, but you can see that the level sets are not perfect. Regardless, the spread of the variance doesn't depend on how big the ellipse is.






                share|cite|improve this answer















                One thing you can try is the following- let $C=C(s)$ be a curve defined for $sin I$, so maybe a line, or a curve like $y=x^2$ or an ellipse. Then define for $mathbf x = (x,y)$,



                $$ f_C(mathbf x) = e^mathbf x - C(s)$$



                The quantity $inf_sin I |mathbf x - C(s)|$ is the shortest distance to the curve $C$.



                In the case $C$ is a line, this should be the same as yours after some redefining of constants, as the shortest distance to a line is obtained by dropping a perpendicular, and hence you will see the intensity die out as you move out perpendicularly from the line, with the exponential decay matching the 1D Gaussian with variance $sigma^2$.



                The function $g(s) := |mathbf x - C(s)|^2$ is differentiable if $C$ is, with derivative



                $$g'(s) = 2(mathbf x - C(s))cdot C'(s)$$
                so the infimum is at a point $C_* = C(s_*)$ where the tangent of the curve is perpendicular to the line joining $mathbf x$ and $C_*$, or in other words, $mathbf x-C_*$ needs to be parallel to the normal vector of the curve. This is a nice picture, but I don't know how it translates into code.



                In the case of an ellipse, say of the form



                $$C(s) = (a cos s, b sin s), s in [0,2π)$$
                Then $C'(s) = (-a sin s, bcos s)$, and the equation to solve is



                $$0 = (mathbf x - C(s))cdot C'(s) = -a(x-acos s)sin s + b(y-bsin s)cos s$$



                I don't see this having an easy-to-write-down solution. You'll also need to check that the second derivative is positive, and then choose the smallest value of $g(s)$ out of all the minimum points.



                On a quick google, I found the following document https://www.geometrictools.com/Documentation/DistancePointEllipseEllipsoid.pdf which seems to go into detail for computing such closest points on an ellipse.



                In the case of a circle of radius $R$, its not so hard. Recenter so that the circle $C$ is entered at the origin, and write $mathbf x = r mathbf u$ where $mathbf u $ is a unit vector, and $r=r(mathbf x) = |mathbf x|$ is the distance of $mathbf x$ to 0. Then



                $$f_C(mathbf x) = e^^2 / 2sigma^2$$



                For an arbitrarily located circle $ = R$, you just need to use $r(mathbf x) = |mathbf x - mathbf x_0|$ instead. If $mathbf x_0 = (x_0,y_0)$, then we arrive at



                $$f_C(x,y) = expleft(frac-left2sigma^2 right)$$



                Naively substituting the circle formula $|mathbf x - mathbf x_0| = R$ with the similar formula for the ellipse $|mathbf x - mathbf x_0| + |mathbf x - mathbf x_1| = R$ ,
                $$f_C(mathbf x) = expleft(frac^22sigma^2right) ?$$



                smallmediumlarge



                gives you something that looks reasonable, but you can see that the level sets are not perfect. Regardless, the spread of the variance doesn't depend on how big the ellipse is.







                share|cite|improve this answer















                share|cite|improve this answer



                share|cite|improve this answer








                edited Jul 26 at 21:48


























                answered Jul 26 at 16:49









                Calvin Khor

                8,03911132




                8,03911132






















                     

                    draft saved


                    draft discarded


























                     


                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmath.stackexchange.com%2fquestions%2f2863523%2fgaussian-along-an-ellipse%23new-answer', 'question_page');

                    );

                    Post as a guest













































































                    Comments

                    Popular posts from this blog

                    What is the equation of a 3D cone with generalised tilt?

                    Relationship between determinant of matrix and determinant of adjoint?

                    Color the edges and diagonals of a regular polygon