Thin lens equation
A converging lens with a 10 cm focal length and an object 30 cm away forms a real image 15 cm behind it. Enter both distances in the same unit to get the image distance and whether the image is real or virtual. Free in your browser.
- Free
- Runs in your browser
- No sign-up
- Your data stays on your device
Run — free
Worked example
- Focal length
- 10
- Object distance
- 30
- Image distance
- 15
- Image type
- real
The thin lens equation is the Gaussian optics identity that places an image from a single thin element: one over the focal length equals one over the object distance plus one over the image distance. This solver accepts a signed focal length f and a signed object distance do, rearranges the identity for the unknown image distance, and returns di equal to f times do divided by do minus f, in the same length unit you supplied. Zero focal length and zero object distance are rejected because one over f and one over do would be undefined. The arithmetic is pure and deterministic, with no network, no sampling, and no clock.
What the thin lens equation states and how image distance is solved
The thin lens equation is the compact paraxial identity one over f equals one over do plus one over di that relates three signed lengths measured from the lens: focal length f, object distance do, and image distance di. Under the Gaussian sign convention used in most introductory physics courses, a real object on the incoming-light side has positive do, a converging convex lens has positive f, and a real image on the outgoing-light side has positive di.
A diverging concave lens carries a negative focal length, and a virtual image that appears on the object side of the lens carries a negative di. Rearrangement for the unknown image location is immediate: one over di equals one over f minus one over do, which multiplies through to the closed form di equals f times do divided by do minus f.
That closed form is exact within the thin-lens paraxial model; it is not a ray-trace, it does not include spherical aberration, and it does not shift the principal planes of a thick element. Classic textbook check: a converging lens with f equal to ten and do equal to thirty places a real image at di equal to fifteen.
What you can do with it
Homework and lab prediction
Compute image distance from textbook focal length and object distance before sketching rays or measuring di on an optical bench.
FAQ
Which sign convention does the thin lens equation use?
Gaussian convention: positive f for a converging lens, positive do for a real object on the incident side, positive di for a real image on the outgoing side. A diverging lens has negative f; a virtual image has negative di.
What happens if the object sits exactly at the focal point?
The rays leave the lens parallel and the image moves off to infinity, which no finite distance can describe. The calculator turns that case away with a clear message instead of showing an infinite number.
How can I tell if the image is real or virtual?
The result says so. A positive image distance means a real image on the far side of the lens, where light actually converges; a negative one means a virtual image on the same side as the object.
Can I use it for a diverging lens?
Yes. Enter the focal length as a negative number, as the usual sign convention requires. For a real object the image distance then comes out negative, which marks a virtual image on the object side.
Does it account for thick lenses or aberrations?
No. It uses the ideal thin-lens model for rays close to the axis. It is not a ray trace, it ignores spherical aberration and it does not shift the principal planes of a thick lens.
Related tools
For developers — API access
Everything on this page is available programmatically. This section is for teams who want to wire it into their own systems; everyone else can just use the tool above.
API endpoint
Prefer to automate it? One authenticated POST creates the task; the result comes back by webhook or a signed link. The same capability also runs here on the web, by email and from Telegram — and soon from our app too.
Call it from your stack
curl -X POST https://api.kit.forhosting.com/phys/thin-lens-equation \
-H "Authorization: Bearer $KIT_KEY" \
-H "Content-Type: application/json" \
-d '{"focal_length":10,"object_distance":30}'const res = await fetch("https://api.kit.forhosting.com/phys/thin-lens-equation", {
method: "POST",
headers: {
"Authorization": `Bearer ${process.env.KIT_KEY}`,
"Content-Type": "application/json"
},
body: JSON.stringify({
"focal_length": 10,
"object_distance": 30
})
});
const { task_id } = await res.json();import os, requests
res = requests.post(
"https://api.kit.forhosting.com/phys/thin-lens-equation",
headers={"Authorization": f"Bearer {os.environ['KIT_KEY']}"},
json={
"focal_length": 10,
"object_distance": 30
},
)
task_id = res.json()["task_id"]<?php
$res = file_get_contents("https://api.kit.forhosting.com/phys/thin-lens-equation", false, stream_context_create([
"http" => [
"method" => "POST",
"header" => "Authorization: Bearer " . getenv("KIT_KEY") . "\r\nContent-Type: application/json",
"content" => '{"focal_length":10,"object_distance":30}',
],
]));
$task = json_decode($res, true);body := bytes.NewBufferString(`{"focal_length":10,"object_distance":30}`)
req, _ := http.NewRequest("POST", "https://api.kit.forhosting.com/phys/thin-lens-equation", body)
req.Header.Set("Authorization", "Bearer "+os.Getenv("KIT_KEY"))
req.Header.Set("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)Example request
{
"focal_length": 10,
"object_distance": 30
}Example response
{
"task_id": "tsk_a1b2c3d4e5f6a1b2c3d4e5f6",
"type": "phys.thin_lens_equation",
"status": "queued",
"_links": {
"result": "/tasks/tsk_…/result"
}
}The API is asynchronous: the call returns a task_id immediately and the result arrives by webhook. Polling is capped at 1 req/s per task.
Pricing
Published price — no tokens, no invented credits. A failed task is never charged.
Limits
max_abs_length | 1000000000000000 |
Errors
| HTTP | Code | Meaning |
|---|---|---|
401 | unauthorized | Missing or invalid API key. |
402 | insufficient_balance | Your balance doesn't cover the task price. |
404 | unknown_type | That task type doesn't exist. |
429 | rate_limited | Too many requests. Use the webhook instead of polling. |
Technical notes
When the object sits exactly at the focal plane the denominator is zero, outgoing rays are parallel, and the image recedes to infinity, so the task fails with invalid_input instead of a non-finite number.
What the thin lens equation states and how image distance is solved
The solver returns the image distance in the same length unit you used for f and do, together with the echoed inputs, an image_type tag of real or virtual from the sign of di, and a short formula string, so homework checks, lab keys, and API clients can display the Gaussian result without re-deriving the algebra. When do equals f the denominator is zero: incident rays from a point on the focal plane leave parallel after refraction, the image is at infinity, and a finite JSON number cannot represent that geometry, so the request is rejected rather than returning Infinity or NaN.
Input contract, aliases, and the do-equals-f error
Magnitudes above the documented ceiling of one quadrillion are rejected so a stray unit conversion does not overflow the isolate. Focal length must be non-zero because one over f is undefined at a plane of zero power; object distance must be non-zero because one over do is undefined when the object sits in the lens plane. POST a JSON body with two required finite numbers: focal_length for f and object_distance for do. Aliases f and focalLength are accepted for the focal length; aliases do, u, s_o, and objectDistance are accepted for the object distance, so spreadsheets, query strings, and typed forms can reuse the same contract. Each field may arrive as a JSON number or as a numeric decimal string, including optional leading signs and scientific notation. Missing fields, empty strings, non-numeric tokens, Infinity, and NaN fail with invalid_input naming the field. The distinctive failure this endpoint exists to catch is object_distance equal to focal_length: that is the object-at-the-focal-plane case, parallel outgoing rays, infinite image distance. On success the body echoes the rounded focal_length and object_distance, the computed image_distance rounded to ten decimal places for stable goldens, image_type real when di is positive or virtual when di is negative, and the formula string one over f equals one over do plus one over di. Pair the response with your own ray sketch if you need a diagram; this endpoint solves the equation for di only and does not emit magnification, orientation tags, or plots.
Where a thin lens equation solver earns its keep
Students meet the thin lens equation when a homework set asks for image location given f and do, when a lab asks them to predict di before measuring it on an optical bench, or when a contest problem wants the Gaussian result without a full ray diagram. Developers call the same contract from scripts to seed deterministic test vectors for optics widgets, to normalize user-entered f and do before a classroom demo, or to satisfy programming-challenge statements that demand image distance rather than a hand-waved sketch. Exam-prep generators need a deterministic oracle that marks wrong the case do equals f instead of silently returning a huge number that a buggy grader might treat as success. Failed validation does not consume balance. Teachers can pre-generate answer keys for modest lengths without trusting opaque calculator apps that silently switch sign conventions or return Infinity as a success payload. Engineering notebooks often reduce a single-element camera or projector layout to this identity before moving to multi-element design; calling a tiny parse API avoids pulling a full optical-design suite for a two-number problem. Keep requests small, pin the rounded image_distance in tests, and you get reproducible Gaussian image locations for homework, LMS plugins, and edge workers without standing up ray-trace infrastructure of your own.
Integration use cases
Exam and LMS auto-grading
Mark thin-lens-equation items with a deterministic oracle that rejects do equal to f as infinite image distance instead of a success payload.
Scripts and optics widgets
Solve 1/f = 1/do + 1/di for di in notebooks, CI fixtures, and teaching demos without importing a full optical-design library.
Technical questions
What is the thin lens equation?
The Gaussian identity 1/f = 1/do + 1/di relating focal length, object distance, and image distance of a single thin lens. This solver rearranges it for di = f·do/(do − f).
How do I compute image distance from f and do?
Send finite non-zero numbers focal_length and object_distance (same length unit). The API returns image_distance and an image_type of real (di > 0) or virtual (di < 0).
What happens when object distance equals the focal length?
The task fails with invalid_input. When do = f the object sits at the focal plane, outgoing rays are parallel, and image distance is infinite, so a finite JSON result is not returned.
What does the thin lens equation solver cost?
The browser tool is free. API requests use prepaid KIT balance at $0.002 per successful call; invalid input is not billed.