DEV Community

Alex Parker
Alex Parker

Posted on

Implementing Optical Vertex Distance Compensation in JavaScript (Glasses to Contacts Formula)

When an eyeglass lens sits 10 to 14 mm in front of the cornea (with 12 mm as the standard clinical vertex distance), its effective optical power at the corneal plane differs from the spectacle plane—especially for prescriptions stronger than ±4.00 D.

In this short technical note, we look at how to implement the optical vertex distance equation in JavaScript for both spherical and toric (astigmatism) prescriptions, and how an interactive vertex distance calculator applies 0.25 D step rounding across principal meridians.

The Vertex Compensation Formula

The standard optical vertex formula is:

Fc = Fg / (1 - d * Fg)
Enter fullscreen mode Exit fullscreen mode

Where:

  • Fg is the spectacle power in diopters (D)
  • d is the vertex distance in meters (e.g., 0.012 for 12 mm)
  • Fc is the compensated power at the corneal plane in diopters (D)

Handling Spherical and Toric (CYL) Prescriptions in JS

For a toric prescription (SPH, CYL, Axis), each principal meridian must be vertex-compensated independently before recombining into sphere and cylinder components:

function roundQuarterDiopter(val) {
  return Math.round(val * 4) / 4;
}

function compensateVertex(fg, vertexMm = 12) {
  const d = vertexMm / 1000;
  return fg / (1 - d * fg);
}

function convertGlassesToContacts({ sph, cyl = 0, axis = 0, vertexMm = 12 }) {
  const m1 = compensateVertex(sph, vertexMm);
  const m2 = compensateVertex(sph + cyl, vertexMm);

  const rawSph = m1;
  const rawCyl = m2 - m1;

  return {
    exactSph: Number(rawSph.toFixed(2)),
    exactCyl: Number(rawCyl.toFixed(2)),
    roundedSph: roundQuarterDiopter(rawSph),
    roundedCyl: roundQuarterDiopter(rawCyl),
    axis
  };
}
Enter fullscreen mode Exit fullscreen mode

Live Reference Tool

If you want to test different vertex distances (10–14 mm) or check how to convert glasses prescription to contacts with instant spherical equivalent and toric meridian breakdowns, you can try the live tool at VertexLensCalc.

Note: Theoretical optical vertex calculations are for educational and software reference purposes only and do not replace a physical contact lens fitting by an optometrist or ophthalmologist.

Top comments (0)