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.

[1]:
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:

[2]:
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()
Plain numbers: 80 × 50, area 3921.5
(a) Plain numbers: 80 × 50, area 3921.5
With px.mm: 0.08 × 0.05, area 3.9215e-03
(b) With px.mm: 0.08 × 0.05, area 3.9215e-03
Figure 1: 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:

[5]:
print("plain:", plain.mass)
print("metric:", metric.mass, "m²")
print("metric:", metric.mass / mm**2, "mm², exact", 80 * 50 - math.pi * 5**2)
plain: 3921.460183660255
metric: 0.003921460183660255 m²
metric: 3921.4601836602556 mm², exact 3921.460183660255

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.

  • 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 for details.