# Optical Forums > Ophthalmic Optics >  Lens Thickness Calculation

## HarryChiling

Javier I hope this helps, I couldn't attach it to a private message.

Estimating Lens Thickness.doc

----------


## HarryChiling

```
//convert diopter to radius
function radius(n, curve) {
    return Math.abs((n-1)/curve)*1000;
}

//back curve formula
function backcurve(thick) {
    return HP - (FC / (1 - (thick / n) * (FC / 1000)));
}


//sagital depth calculation
function sag(radius, diameter) {
    return radius - Math.sqrt(Math.pow(radius,2) - Math.pow((diameter/2),2));
}


//iterative accurate thickness function
function thickness(thick) {
    BC = backcurve(thick);
    radBC = radius(n,BC);
    sagBC = sag(radBC, MBS);
    
    if (HP < 0) {
        actualthick = sagBC + t - sagFC;
    } else {
        actualthick = sagFC + t - sagBC;
    }
    
    if (Math.abs(thick - actualthick) > thresh) {
        thickness(thick + (actualthick-thick)/2);
    }
    return actualthick;
}


var sph = -4.00;
var cyl = -1.00;
var axis = 145;
var pd = 32;
var A = 52;
var dbl = 18;
var ED = 53;
var n = 1.50;
var FC = 4.00;
var t = 1.5;

var thresh = 0.1;

var decentration = Math.abs(((A + dbl) / 2) - pd); 
var MBS = ED + decentration;

var radFC = radius(n,FC);
var sagFC = sag(radFC, MBS);

var HP = (Math.abs(sph) >= Math.abs(sph + cyl))? sph : sph + cyl;

var approxthick = Math.abs((Math.pow(MBS/2, 2) * HP) / (2000 * (n - 1))) + t;

var actualthick = thickness(approxthick);
```

Here is an iterative javascript function that illustrates an accurate thickness calculation.

Here is the fiddle : http://jsfiddle.net/harrychiling/wy7bjs2t/

----------


## lensgrinder

Nice work Harry!

Have you considered a while loop in your javascript?  I use one in my iOS app and my online thickness calculator located at http://mccardle.me/brent/calculators/
I find the approximate thickness and add 1 to it.  Then subtract the approximate thickness from that value until it reaches a designated threshold.  All while calculating the back vertex power.

----------


## HarryChiling

> Nice work Harry!
> 
> Have you considered a while loop in your javascript?  I use one in my iOS app and my online thickness calculator located at http://mccardle.me/brent/calculators/
> I find the approximate thickness and add 1 to it.  Then subtract the approximate thickness from that value until it reaches a designated threshold.  All while calculating the back vertex power.


Brent so great to hear from you.  I have a version that uses a while loop in a previous calculator.  If you look at the thickness function, the function is recursive so it calls itself with every iteration using the more accurately calculated thickness to compute a new back vertex and then using that back vertex to calculate a new more accurate thickness, then this new thickness is compared to the thickness passed into the function and if a certain threshold is attained then the routine stops.  For diagnostic and to see the inner workings you could add an array and push each iterations values into the array to see how many iterations are performed before the thickness normalizes.  Code and example below:



```
//convert diopter to radius
function radius(n, curve) {
    return Math.abs((n-1)/curve)*1000;
}


//back curve formula
function backcurve(thick) {
    return HP - (FC / (1 - (thick / n) * (FC / 1000)));
}




//sagital depth calculation
function sag(radius, diameter) {
    return radius - Math.sqrt(Math.pow(radius,2) - Math.pow((diameter/2),2));
}




//iterative accurate thickness function
function thickness(thick) {
    BC = backcurve(thick);
    radBC = radius(n,BC);
    sagBC = sag(radBC, MBS);
    
    if (HP < 0) {
        actualthick = sagBC + t - sagFC;
    } else {
        actualthick = sagFC + t - sagBC;
    }
    
    if (Math.abs(thick - actualthick) > thresh) {
        iter.push([BC.toFixed(4), actualthick.toFixed(4)]);
        thickness(thick + (actualthick-thick)/2);
    }
    return actualthick;
}




var sph = -4.00;
var cyl = -1.00;
var axis = 145;
var pd = 32;
var A = 52;
var dbl = 18;
var ED = 53;
var n = 1.50;
var FC = 4.00;
var t = 1.5;
var iter = [];


var thresh = 0.1;


var decentration = Math.abs(((A + dbl) / 2) - pd); 
var MBS = ED + decentration;


var radFC = radius(n,FC);
var sagFC = sag(radFC, MBS);


var HP = (Math.abs(sph) >= Math.abs(sph + cyl))? sph : sph + cyl;


var approxthick = Math.abs((Math.pow(MBS/2, 2) * HP) / (2000 * (n - 1))) + t;


var actualthick = thickness(approxthick);
```

fiddle: http://jsfiddle.net/harrychiling/wy7bjs2t/1/

----------


## HarryChiling

Brent,

It looks like we are working on some of the same things, your site shows a calculator or software that I demoed here a few months back but I like your better.  I have a few modules I can send your way if you are interested.

----------


## HarryChiling

I have written all the functions to interact as well, the design goal is to eventually as time permits allow a one page setup where a prescription is entered and the calculator checks the script to:


ANSI standardThe base curve is optimal (along the 180 meridian for a panoramic lens)Vertical ImbalanceCut out for the PAL (incorporating the trace module I demo'ed in another thread, I have a tracer on the way but reading an OMA file I have already demonstrated in an earlier video, now I need to incorporate the communications)

I have a functional Augmented Reality module that I may or may not have demo'ed here that overlays a frame on a live video stream of a patient.

I have a Digital Centration module that I may or may not have demo'ed on here (gave a lecture on it about a year ago where I took the PD of an audience member)

Visual Acuity chart which I have posted here in the forums because I saw a lack of this tool in many offices and thought it would be of use to the industry NOW, rather than sitting on it.

----------


## lensgrinder

> Brent so great to hear from you.  I have a version that uses a while loop in a previous calculator.  If you look at the thickness function, the function is recursive so it calls itself with every iteration using the more accurately calculated thickness to compute a new back vertex and then using that back vertex to calculate a new more accurate thickness, then this new thickness is compared to the thickness passed into the function and if a certain threshold is attained then the routine stops.


As always, great to hear from you too Harry.
I see it now, I don't do a lot in javascript so it took a minute.
I just noticed that your calculation and mine were different and I thought this would be the cause.



> Brent,
> 
> It looks like we are working on some of the same things, your site shows a calculator or software that I demoed here a few months back but I like your better.  I have a few modules I can send your way if you are interested.


I would love to see them!




> I have written all the functions to interact as well, the design goal is to eventually as time permits allow a one page setup where a prescription is entered and the calculator checks the script to:
> 
> 
> ANSI standardThe base curve is optimal (along the 180 meridian for a panoramic lens)Vertical ImbalanceCut out for the PAL (incorporating the trace module I demo'ed in another thread, I have a tracer on the way but reading an OMA file I have already demonstrated in an earlier video, now I need to incorporate the communications)
> 
> I have a functional Augmented Reality module that I may or may not have demo'ed here that overlays a frame on a live video stream of a patient.
> 
> I have a Digital Centration module that I may or may not have demo'ed on here (gave a lecture on it about a year ago where I took the PD of an audience member)
> 
> Visual Acuity chart which I have posted here in the forums because I saw a lack of this tool in many offices and thought it would be of use to the industry NOW, rather than sitting on it.


If only we had more time in the day or were independently wealthy!

----------


## HarryChiling

I would love to see them!

i'll throw them up on the web this week and send you the link.



If only we had more time in the day or were independently wealthy!

you ain't kidding, ideas are a plenty time and money are the scarce resources.

----------


## jhprog

Hello Harry,

Thank you very much for you code.

So you are going to communicate with a Tracer via the WebBrowser?

----------


## HarryChiling

> Hello Harry,
> 
> Thank you very much for you code.
> 
> So you are going to communicate with a Tracer via the WebBrowser?


Yes, the api is available through Chrome.

https://developer.chrome.com/apps/serial

Which makes transfer of trace files trivial.

----------


## jhprog

Hello Again,

I had some other things to handle and could not dedicate time to this, but now I have come back to calculate the Lens Thickness at any point of the Lens.

I am using the formula for the Toroid Saggita (Following the Harris paper: "The Sagitta and Lens Thickness"

saggita=rb*(1-(Pow(Pow(1-((ra/rb)*(1-Pow(1-((x*x)/(ra*ra)),0.5))),2)-((y*y)/(rb*rb)),0.5)))

Being:
rb= radius for weak in mts (sorry if the name is not the right one)
ra= radius for cross in mts
x and y: position in mts

In order to calculate the Radius I follow this procedure:

  vergence_surface1=(n-1)/FrontCurve
  vergence_surface2=vergence_surface1-(CT/n)

  power_surface2=1/vergence_surface2
  surface2Power_weak.f=sph-power_surface2
  surface2Power_cross.f=(sph+cyl)-power_surface2

  radius_weak=(n-1)/surface2Power_weak
  radius_cross=(n-1)/surface2Power_cross

So following the general formula

Thickness= CenterThickness - Saggita 1st Surface + Saggita 2nd Surface.


I am not getting the right results. Do you know what I am doing wrong? 

Many thanks in advance,

----------


## HarryChiling

> Hello Again,
> 
> I had some other things to handle and could not dedicate time to this, but now I have come back to calculate the Lens Thickness at any point of the Lens.
> 
> I am using the formula for the Toroid Saggita (Following the Harris paper: "The Sagitta and Lens Thickness"
> 
> saggita=rb*(1-(Pow(Pow(1-((ra/rb)*(1-Pow(1-((x*x)/(ra*ra)),0.5))),2)-((y*y)/(rb*rb)),0.5)))
> 
> Being:
> ...


The "y" in your above equation is refering to a tilted coordinate system.  In essence the whole coordinate system is being tilted so that the y plane is parallel to the coordinate system of the optical axis.  This allows the the angle of one of the off axis components to be to be viewed from the edge in essence eliminating the need for a differential calculation.  We are simplifying the the curve from three demensions to a 2 demensional ellipse (more accurately expressed in the paper as Oval of Cassini).

The "yalpha" angle must be computed first then put into your formula where you have the "y" variable. 

The equation you provided is only for a horizontally configured for decentration along one axis, if you plan to provide a point by point thickness analysis using the formula for the paper you will need to compute the "ybeta" angle as well and change your "y" variable to:

yalpha = ya * cos(a) + yb sin(a)
ybeta = -ya * sin(a) + yb * cos(a)

----------


## jhprog

Hello Harry,

Thank you for your answer. Just another question.

I am thinking of using the Harris approach for lens thickness calculation. Do you think is a good option? If so is there any paper or example so i could understand how to apply it? Because I dont really understand how do I have to use it properly.

Thank you another time.

----------


## HarryChiling

I have a working example with the code below, you still have to iterate through using the method I provided above to determine the correct back curve, then you would use those values in the Harris method, could be just as simple as modifying my previous example to return an object containing the variables needed and then using those in the following Harris method.



```
// helper functions
function sin(x) {return Math.sin(x);}
function cos(x) {return Math.cos(x);}
function rad(x) {return Math.PI * x / 180;}
function deg(x) {return x * 180 / Math.PI;}
function sqrt(x) {return Math.sqrt(x);}
function pow(x) {return Math.pow(x, 2);}
function abs(x) {return Math.abs(x);}


function compute() {
    var sph, cyl, axis, x, y, n;


    sph = 20;
    cyl = -10;
    axis = 30;
    n = 1.6;
    x = 25; //ya in paper
    y = -5; //yb in paper


    //principal and secondary meridians
    var prin_mer = sph;
    var secon_mer = sph + cyl;


    var Fa, Fb, a, ra, rb, yalpha, ybeta, sag;


    //set the torus up properly and set the rotation
    if (prin_mer >= secon_mer) {
        Fa = prin_mer;
        Fb = secon_mer;
        a = axis;
    } else {
        Fa = secon_mer;
        Fb = prin_mer;
        a = (axis > 90) ? axis - 90 : axis + 90;
    }


    //radius of the torus
    ra = (n - 1) / Fa;
    rb = (n - 1) / Fb;


    //convert radius from m to mm
    ra *= 1000;
    rb *= 1000;


    //point on the tilted coordinate system
    yalpha = x * cos(rad(a)) + y * sin(rad(a));
    ybeta = -x * sin(rad(a)) + y * cos(rad(a));


    var step1, step2, step3;


    //broken into steps for easier computation
    step1 = 1 - sqrt(1 - pow(yalpha) / pow(ra));
    step2 = pow(1 - (ra / rb) * step1);
    step3 = sqrt(step2 - pow(ybeta) / pow(rb));
    sag = rb * (1 - step3);


    var lensform;


    //define the form of the lens
    if ((Fa > 0 && Fb > 0) || (Fa < 0 && Fb < 0)) {
        // these are toric lenses
        if (abs(Fa) > abs(Fb)) {
            lensform = "Tire";
        }
        if (abs(Fa) < abs(Fb)) {
            lensform = "Barrel";
        }
        if (Fa == Fb) {
            lensform = "Sphere";
        }


    } else {
        //these are pulley lenses
        if (abs(Fa) > abs(Fb)) {
            lensform = "Pulley";
        }
        if (abs(Fa) < abs(Fb)) {
            lensform = "Capstan";
        }
        if (Fa == Fb) {
            if (Fa >= 0) {
                lensform = "Pulley";
            } else {
                lensform = "Capstan";
            }
        }
    }
    
    alert("The lens is a " + lensform + " with a Sag: " + sag);
}
```

Here is a fiddle with the code: http://jsfiddle.net/harrychiling/x39ssowd/

----------


## jhprog

Hello 

Thank you for the code. I have applied and I just need to understand the results. Sorry for my questions I am really new/newbie to this matter and I have lots of doubts. I have found some bibliografy... but I need an indepth understanding. And bibliography do not deal with point to point depth calculation.

Before you continue reading sorry for the extension, I wanted to explain all the methods that I have tried so far.

If you set:
    sph = -4.00;
    cyl = -1.00;
    axis = 0;
    n = 1.5;
    x = 25;
    y = 0;

The result is: -2.525 in mm? How do I have to understand that?

I will explain my findings to check what I am doing wrong.

I take a lens calculation of -4.00 DS / -1.00 DC x 180. Let's assume we take a Front Curve of 3.00 (Crown Glass Index). Center Thickness is 1.5 mm. This give us that:

.Surface 1 (external) will have an Spherical Power of: 2.878 
.Surface 2 (internal) Back Curve will be: -9.802@180 / -10.802@90

Now I apply this to the Toroid at Position x=25, y=0

.Saggita1: 1.812 mm
.Saggita2: -6.561 mm

-> I have gone a littler bit further. I have calculated the Dioptric Power Matrix for those surfaces and applied to the same position: x=25, y=0
.Saggita1: 1.802 mm
.Saggita2: -6.139 mm

-> Following Harry's paper for thin Lenses F=F1+F2
.Saggita : -4.33 mm

-> This gives me a Thickness of 5.8 mm. Which is far from expected value of 4.4 mm

I have tested the BC values with the SolaRX program for the same lens configuration the BC is: -9.62@180 / -10.62@90. I think I have to reduce the curve for the Pad compensation (I have not find the way to apply that) But the BC's that I am getting right now are fine enough to get a "relatively" good result.


I have tried almost all combinations and I can not find the right answer. 

Any help will be much appreciated

----------


## MakeOptics

> Hello 
> 
> Thank you for the code. I have applied and I just need to understand the results. Sorry for my questions I am really new/newbie to this matter and I have lots of doubts. I have found some bibliografy... but I need an indepth understanding. And bibliography do not deal with point to point depth calculation.
> 
> Before you continue reading sorry for the extension, I wanted to explain all the methods that I have tried so far.
> 
> If you set:
>     sph = -4.00;
>     cyl = -1.00;
> ...


Please supply the frame A, Dbl, ED, and the PD and I will walk through the example with you.  You only reduce the curve on the tool, the lens will have the computed curve the tool will have the pad thickness taken off of the radius of the tool so that the tool with the pad on it is the equal but opposite of the back curve.

----------


## jhprog

Hello,

Right now I am still on the calculation of the thickness of the lens. I have taken a 50mm round lens as example I want to calculate the thickness at any point. Without taking into account the frame.

----------


## lensgrinder

> Hello,
> 
> Right now I am still on the calculation of the thickness of the lens. I have taken a 50mm round lens as example I want to calculate the thickness at any point. Without taking into account the frame.


Here is a link to the formula worked out. 

http://optical-tool.me/1h7huYs

You will have to run the back vertex, back radius, and sag through a loop.
If the front sag - back sag <=  0 you do not need to run it through a loop
This link calculated front sag - back sag <= 0 so it uses 1.5 for the thickness through the calculations.

----------


## MakeOptics

> Hello,
> 
> Right now I am still on the calculation of the thickness of the lens. I have taken a 50mm round lens as example I want to calculate the thickness at any point. Without taking into account the frame.


I have combined the two methods which was the intent.  Use the iterations to determine a more accurate back curve, then use the Harris method to compute the thickness.  I did not use his matrix form as he describes it as an approximation.  You should get accurate results.  Since you are comparing to a lab calculator I have put the tool index of 1.53 in and the curve gets converted for you.  The protection is just there to prevent an oops, their is no passwords so you can unlock the book and the sheets and change to your hearts content.  View the formulas I tried to be as verbose as possible to avoid any confusion.

----------


## jhprog

Hello 

This excel has been really helpful!!!! it's been a masterclass. 

THANK YOU VERY MUCH.

Is there something or bibliography that I could read in order to do this lens thickness calculation for asferic lenses?

----------


## MakeOptics

> Hello 
> 
> This excel has been really helpful!!!! it's been a masterclass. 
> 
> THANK YOU VERY MUCH.
> 
> Is there something or bibliography that I could read in order to do this lens thickness calculation for asferic lenses?


Professor Mo Jalie outlines a simple expression in his paper on aspherics:

http://www.optometry.co.uk/uploads/a...ie20050325.pdf

In the calculations if you were to substitute out the sag equation in the first portion with the one in the paper and then in the second step (Harris method) sub out the ra and rb variables with localized radius values you would get the answer you are looking for.

Keep in mind the aspherics equation mentioned in the above paper is for simple rotationally symmetrical shapes, lenses like a Seiko MX as an example have a spherical center and at a certain radius from the center point start aspherizing calculating that would require a bit more sophistication and imposing limits on the your formula's domain and range.

I am glad you enjoyed.

Updated with Aspherics for the Front Curve, I am sorry but if you ask for the back curve I will have to stop you there, that algorithm can be used to create point files and consequently SV freeform lenses which is something I have predicted coming down the pipeline where opticians provide a lab with a point file and get a lens back.  You should be able to easily move the surface equations to the back and make them atoric if you choose.  I just can't give that away right now, hope you understand.

That's funny I gave a course on aberrations a few years back and every set of eyes in the room was glazed over since we ray traced every aberration and derived formula's in a one hour long class, real intensive.  The only individual that kept up and had great questions was Barry Santini.  The reviews on that course were good but I don't think the warning that the course was going to be math intensive was taken seriously.

----------


## Emily Chen

Great! thank you for your share :Bounce:

----------

