Coordinate to Relative Offset Converter
Convert absolute coordinates to relative offsets within a bounding rectangle. Configurable range (0-65535 default). Supports batch and inverse modes.
About
Mapping absolute pixel coordinates to normalized relative offsets is a routine requirement in HID digitizer drivers, touch-panel firmware, and game-engine input pipelines. The standard range 0 - 65535 (0xFFFF) originates from the USB HID specification for absolute pointing devices. A miscalculated offset shifts cursor registration across the entire display surface - on a 3840ร2160 panel, a single-bit error at the high end of the range corresponds to roughly 0.06 px, but at coarser ranges the error budget grows fast. This tool computes r = ((p โ o) รท s) ร R with explicit clamping, batch input, and an inverse mode that recovers absolute coordinates from relative values. It assumes a linear, axis-aligned bounding rectangle; rotated or perspective-distorted bounds require affine correction not covered here.
Formulas
The forward conversion maps an absolute coordinate p into the relative range [0, R] given a bounding rectangle with origin o and size s:
The inverse conversion recovers the absolute coordinate from a relative offset:
Applied independently per axis:
Where: px, py = absolute input coordinates. x0, y0 = bounding rectangle origin (top-left). w, h = bounding rectangle width and height. R = maximum range value (default 65535). rx, ry = resulting relative offsets. clamp restricts output to [0, R], preventing out-of-bounds values when the input coordinate falls outside the rectangle.
Reference Data
| Range Name | Max Value | Hex | Bits | Common Use | Resolution on 1920 px |
|---|---|---|---|---|---|
| USB HID Absolute | 65535 | 0xFFFF | 16 | Touch digitizers, pen tablets | 0.029 px |
| Byte Normalized | 255 | 0xFF | 8 | Low-res controllers, MIDI | 7.53 px |
| Percentage | 100 | 0x64 | 7 | CSS / UI layout | 19.2 px |
| Per-mille | 1000 | 0x3E8 | 10 | Financial, fine positioning | 1.92 px |
| Unity Float | 1.0 | - | 64 (f64) | Game engines, shaders | 5.2ร10โ13 px |
| 12-bit ADC | 4095 | 0xFFF | 12 | Resistive touchscreens | 0.469 px |
| 10-bit ADC | 1023 | 0x3FF | 10 | Legacy analog sticks | 1.877 px |
| Windows Ink | 65535 | 0xFFFF | 16 | Windows pen protocol | 0.029 px |
| Android MotionEvent | 1.0 | - | 32 (f32) | Normalized touch coords | 1.1ร10โ4 px |
| Wacom EMR | 32767 | 0x7FFF | 15 | Wacom tablet report | 0.059 px |
| 24-bit Extended | 16777215 | 0xFFFFFF | 24 | High-precision scientific | 1.1ร10โ4 px |
| SVG viewBox | Custom | - | - | Scalable vector graphics | Depends on viewBox |