--- jupyter: description: 'Units in planex2d: the geometry itself has no unit; px.mm, px.inch and the other factors convert to meters, and the readers of DXF and KiCad files return meters too.' --- # Units planex2d does not impose a unit system. A number is a length in whatever unit you choose, and an area is in that unit squared. The factors `px.mm`, `px.cm`, `px.m`, `px.um`, `px.inch` and `px.mil` state what a number means; with them, the geometry is in meters. ```python import math import planex as px ``` ## The same plate twice The example is a plate of 80 × 50 mm with a hole of 10 mm diameter, drawn twice: once in plain numbers, counting in millimeters, and once with the factors, in meters: ```python plain = px.QuickSketch().Rectangle(80, 50).Face() - px.Circle((40, 25), 5).Face() mm = px.mm metric = px.QuickSketch().Rectangle(80 * mm, 50 * mm).Face() - px.Circle((40 * mm, 25 * mm), 5 * mm).Face() ``` ```python nbsphinx="hidden" from docs_figures import Row ``` ```python nbsphinx="hide-input" Row((plain, f"Plain numbers: 80 × 50, area {plain.mass:.1f}"), (metric, f"With px.mm: 0.08 × 0.05, area {metric.mass:.4e}"), caption="The same plate in plain numbers and in meters") ``` Both are the same plate, and only the numbers differ. The first area is in mm² and the second in m². Divided by `px.mm**2`, the second area is in mm² again: ```python print("plain:", plain.mass) print("metric:", metric.mass, "m²") print("metric:", metric.mass / mm**2, "mm², exact", 80 * 50 - math.pi * 5**2) ``` ## The factors | Factor | In meters | |---|---| | `px.m` | 1 | | `px.cm` | 0.01 | | `px.mm` | 0.001 | | `px.um` | 10⁻⁶ | | `px.inch` | 0.0254 | | `px.mil` | 2.54 · 10⁻⁵ (a thousandth of an inch) | ## Where units come in - **Files.** `px.FromDXF` reads the drawing's unit from its header and returns its wires in meters; `unit=` sets the unit instead. `px.WriteDXF` writes meters unless `unit=` is given, for example `unit=px.mm`. KiCad boards are read in meters, and `px.WriteKiCad` takes `unit=` as well. See [Files](../files.md). - **Simulations.** Material constants have to be in the same unit as the geometry. A part drawn in millimeters and solved in NGSolve needs a conductivity in W/(mm K), not W/(m K). - **Resolution.** planex2d resolves lengths down to about 10⁻¹⁴ relative to the coordinates, or 10⁻¹⁴ absolute for coordinates below 1. OpenCASCADE works with an absolute tolerance of 10⁻⁷, so after the export, a feature smaller than that, in the chosen unit, is lost. See [Tolerances](tolerances.md) for details.