Focal length calculator
Measure where the object and its image sit and get the focal length: an object at 30 with its image at 15 means a focal length of 10, a converging lens. Built for lab checks and homework. Free in your browser.
- Free
- Runs in your browser
- No sign-up
- Your data stays on your device
Run — free
Runs in your browser. Free, unlimited — your data never leaves this page.
This focal length calculator takes an object distance and an image distance and returns the thin-lens focal length from the Gaussian lens equation used in introductory geometric optics. The identities are fully deterministic: one over f equals one over do plus one over di, which rearranges to f equals do times di over do plus di. Classic checks include a real image with do equals thirty and di equals fifteen, which yields f equals ten for a converging lens, and a virtual image with do equals five and di equals negative ten, which still yields f equals ten. The engine uses only finite arithmetic with no network calls, no sampling, and no date-dependent shortcuts.
Where focal-length checks fit in study, labs, and software
Students meet this solve when a lab measures object and image distances for an unknown lens, when a homework set asks them to find f from measured do and di, or when a contest problem wants the lens power without a full ray diagram. Teachers can pre-generate answer keys for modest lengths without trusting opaque calculator apps that silently switch sign conventions or invert the formula.
Developers call the same contract from scripts to seed deterministic test vectors for optics widgets, to normalize user-entered do and di before a classroom demo, or to satisfy programming-challenge statements that demand f rather than a hand-waved sketch. Contest practice often needs a fast, offline source of focal lengths so solutions can be checked without graphing calculators under time pressure. Product and education tools use the solve when a learner types object and image distances and the UI must show focal length and whether the lens is converging or diverging.
What you can do with it
Homework and lab checks
Compute f from textbook or measured do and di; verify converging vs diverging before sketching rays.
Tutoring and optics widgets
Normalize user-entered object and image distances for interactive lessons and quick lens-power demos.
FAQ
What does the focal length calculator cost?
It is free in your browser on this page.
How is focal length defined here?
Positive f is converging; negative f is diverging under the Gaussian convention.
Why are results rounded to a precision?
Default precision is 10 decimal places; you can set precision from 0 to 15.
How do I find focal length from object and image distance?
Multiply the two distances and divide by their sum: f equals do times di over do plus di. With an object at 30 and an image at 15, the focal length is 10.
What does a negative image distance mean?
It means the image is virtual, on the same side as the object. The formula still works: an object at 5 with an image at -10 also gives a focal length of 10.
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/optics/focal-length \
-H "Authorization: Bearer $KIT_KEY" \
-H "Content-Type: application/json" \
-d '{"object_distance":30,"image_distance":15}'const res = await fetch("https://api.kit.forhosting.com/optics/focal-length", {
method: "POST",
headers: {
"Authorization": `Bearer ${process.env.KIT_KEY}`,
"Content-Type": "application/json"
},
body: JSON.stringify({
"object_distance": 30,
"image_distance": 15
})
});
const { task_id } = await res.json();import os, requests
res = requests.post(
"https://api.kit.forhosting.com/optics/focal-length",
headers={"Authorization": f"Bearer {os.environ['KIT_KEY']}"},
json={
"object_distance": 30,
"image_distance": 15
},
)
task_id = res.json()["task_id"]<?php
$res = file_get_contents("https://api.kit.forhosting.com/optics/focal-length", false, stream_context_create([
"http" => [
"method" => "POST",
"header" => "Authorization: Bearer " . getenv("KIT_KEY") . "\r\nContent-Type: application/json",
"content" => '{"object_distance":30,"image_distance":15}',
],
]));
$task = json_decode($res, true);body := bytes.NewBufferString(`{"object_distance":30,"image_distance":15}`)
req, _ := http.NewRequest("POST", "https://api.kit.forhosting.com/optics/focal-length", body)
req.Header.Set("Authorization", "Bearer "+os.Getenv("KIT_KEY"))
req.Header.Set("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)Example request
{
"object_distance": 30,
"image_distance": 15
}Example response
{
"task_id": "tsk_a1b2c3d4e5f6a1b2c3d4e5f6",
"type": "optics.focal_length",
"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
What the focal-length solve returns and how to read the fields
The thin-lens equation relates three signed lengths along the optical axis: the object distance do, the image distance di, and the focal length f. Solving for the unknown focal length gives f equals the product of do and di divided by do plus di. Under the Gaussian sign convention used here, a positive f means a converging lens and a negative f means a diverging lens; positive di usually marks a real image on the transmission side while negative di marks a virtual image. This calculator returns the normalized object_distance and image_distance you supplied, the computed focal_length rounded to the requested precision, a lens_type tag of converging or diverging from the sign of f, the precision used, a short formula string, and the method tag focal_length. There is no approximate ray-trace path and no random sampling of surfaces: the engine either builds an exact floating-point f inside the supported length range or rejects the input with invalid_input. Rejected cases include missing do or di, non-finite values, magnitudes above the documented ceiling, any object or image distance that is zero or numerically zero, and the special case do plus di equals zero where the reciprocal sum vanishes and f is undefined.
How object and image distances are read and stay reproducible
Optional leading plus signs and scientific notation on length strings are allowed when they parse as finite decimals; embedded spaces, hex prefixes, and non-numeric tokens are rejected with a clear message so a bad cell does not become a wrong focal length. The preferred fields are object_distance for do and image_distance for di, but aliases do, u, s_o, and objectDistance for the object distance, and di, v, s_i, and imageDistance for the image distance, are accepted so spreadsheets, query strings, and typed forms can reuse the same contract. Zero for either distance is never valid: if absolute do or di is at or below a tiny epsilon, the request fails with invalid_input because one over that length is undefined. Equally important, when do equals the negative of di the sum is zero and the formula for f divides by zero, so that geometry is rejected with a clear invalid_input message rather than returning Infinity or NaN. An optional precision field, with aliases decimals and dp, chooses how many decimal places to expose for the numeric fields, defaulting to ten and capped at fifteen so JSON goldens stay stable. Pair the free browser run on this page with the priced API when you need the identical mathematical result inside an automated pipeline without re-implementing the focal-length formula yourself.
Where focal-length checks fit in study, labs, and software
On this page the work runs entirely in your browser; through the API each successful lookup costs $0.002, failed validation is not charged, and nothing is stored after the response returns. That split — free interactive exploration and a priced, identical API — matches the rest of the KIT tier-A catalog and lets you move from a classroom demo to an automated pipeline without changing the mathematical result. Pair it with the thin-lens image-distance tool and other math and science endpoints when you are building a small lab of free, deterministic helpers for geometry, algebra, and introductory physics.
Integration use cases
Deterministic test fixtures
Generate reproducible focal_length values for unit tests, property checks, and CI assertions.
Technical questions
What happens if object distance plus image distance is zero?
The input is rejected with invalid_input. When do + di = 0, the reciprocal sum vanishes and f is undefined.
Can either distance be zero?
No. do = 0 or di = 0 makes 1/do or 1/di undefined; both cases return invalid_input.