Human eye defects: computing the exact lens power to fix myopia and hypermetropia, in JavaScript

2026-11-28来源 dev.toEnglish

Glasses don't just "correct" vision in some vague sense — the lens power prescribed is a specific number of dioptres, computed from exactly where your eye's far point or near point has drifted to. Two formulas, two very different defects.

Myopia (short-sightedness)

The eye focuses parallel rays before the retina, so distant objects blur; the far point has moved in from infinity to some finite distance (say 5 m). A concave (diverging) lens of focal length equal to minus that far point sends parallel rays out as if they came from the far point itself:

P = −1 / (far point, in metres)

Hypermetropia (long-sightedness)

The eye can't focus close objects; the near point has moved out past the normal 25 cm (say to 1 m). A convex (converging) lens must take an object at 25 cm and form a virtual image at the person's own near point, so the lens formula 1/f = 1/v − 1/u is used directly with u = −25 cm, v = −(near point).

Checked in JavaScript

// Myopia: far point at 5 m instead of infinity const farPoint = 5; // m const Pmyopia = -1 / farPoint; console.log(Pmyopia.toFixed(2)); // -0.20 (D, concave lens) // Hypermetropia: near point at 1 m instead of 0.25 m const u = -0.25, v = -1; // sign convention, object/image distances in m const Phyper = 1 / v - 1 / u; console.log(Phyper.toFixed(2)); // 3.00 (D, convex lens) 

A far point of 5 m needs a lens of −0.20 D — a fairly mild correction. A near point that has retreated to 1 m needs +3.00 D, a much stronger convex lens, because the eye has to do 3 extra dioptres of focusing work that it can no longer supply on its own.

Why the signs matter so much here

Both formulas use the same sign convention (distances measured from the lens, real is positive in the direction light travels for a real object), but get opposite-signed lens powers because the two defects need opposite kinds of correction: concave lenses have negative power and converge rays less, convex lenses have positive power and converge rays more.

Common mistake

Students often plug the far point straight in without the negative sign, or confuse which distance (far point vs near point) each defect's formula needs — myopia only ever needs the far point, hypermetropia only ever needs the near point and the standard 25 cm.

Practise it online

PractiSci's human eye lab lets you drag the far point and near point of a simulated eye and watch the required correcting lens power update live: Human eye defects lab. The Ray Optics topic guide has more lens-formula practice.

Full disclosure: I build PractiSci, a free virtual physics and chemistry lab for Class 11–12.

原文:https://www.a8q9.cn/en/article/human-eye-defects-computing-the-exact-lens-power-to-fix-myopia-and-hypermetropia-c0c4b8.html

相关文章