6 Measuring Things: Contexts and Units
Five records that say “millimetres, radians, and anything closer than a ten-millionth is the same point.” Why a millimetre is three types at once, how an inch file smuggles in a millimetre anyway, and what a kernel’s tolerance is doing in an exchange file.
Every number in the geometry of the block file — the 60. in a corner point, the 1. in a direction, the 3. in a circle’s radius later on — is a bare real. Nothing on the record says what unit it is in. That information lives in one place, and every geometric representation points at it:
#10 = ADVANCED_BREP_SHAPE_REPRESENTATION('',(#11,#15),#165);
...
#165 = ( GEOMETRIC_REPRESENTATION_CONTEXT(3)
GLOBAL_UNCERTAINTY_ASSIGNED_CONTEXT((#169))
GLOBAL_UNIT_ASSIGNED_CONTEXT((#166,#167,#168))
REPRESENTATION_CONTEXT('Context #1','3D Context with UNIT and UNCERTAINTY') );
#166 = ( LENGTH_UNIT() NAMED_UNIT(*) SI_UNIT(.MILLI.,.METRE.) );
#167 = ( NAMED_UNIT(*) PLANE_ANGLE_UNIT() SI_UNIT($,.RADIAN.) );
#168 = ( NAMED_UNIT(*) SI_UNIT($,.STERADIAN.) SOLID_ANGLE_UNIT() );
#169 = UNCERTAINTY_MEASURE_WITH_UNIT(LENGTH_MEASURE(1.E-07),#166,
'distance_accuracy_value','confusion accuracy');Referred to above: 155 records from block.step
#11 = AXIS2_PLACEMENT_3D('',#12,#13,#14);
#12 = CARTESIAN_POINT('',(0.,0.,0.));
#13 = DIRECTION('',(0.,0.,1.));
#14 = DIRECTION('',(1.,0.,-0.));
#15 = MANIFOLD_SOLID_BREP('',#16);
#16 = CLOSED_SHELL('',(#17,#57,#97,#119,#141,#153));
#17 = ADVANCED_FACE('',(#18),#52,.F.);
#18 = FACE_BOUND('',#19,.F.);
#19 = EDGE_LOOP('',(#20,#30,#38,#46));
#20 = ORIENTED_EDGE('',*,*,#21,.F.);
#21 = EDGE_CURVE('',#22,#24,#26,.T.);
#22 = VERTEX_POINT('',#23);
#23 = CARTESIAN_POINT('',(0.,0.,0.));
#24 = VERTEX_POINT('',#25);
#25 = CARTESIAN_POINT('',(0.,0.,10.));
#26 = LINE('',#27,#28);
#27 = CARTESIAN_POINT('',(0.,0.,0.));
#28 = VECTOR('',#29,1.);
#29 = DIRECTION('',(0.,0.,1.));
#30 = ORIENTED_EDGE('',*,*,#31,.T.);
#31 = EDGE_CURVE('',#22,#32,#34,.T.);
#32 = VERTEX_POINT('',#33);
#33 = CARTESIAN_POINT('',(0.,20.,0.));
#34 = LINE('',#35,#36);
#35 = CARTESIAN_POINT('',(0.,0.,0.));
#36 = VECTOR('',#37,1.);
#37 = DIRECTION('',(0.,1.,0.));
#38 = ORIENTED_EDGE('',*,*,#39,.T.);
#39 = EDGE_CURVE('',#32,#40,#42,.T.);
#40 = VERTEX_POINT('',#41);
#41 = CARTESIAN_POINT('',(0.,20.,10.));
#42 = LINE('',#43,#44);
#43 = CARTESIAN_POINT('',(0.,20.,0.));
#44 = VECTOR('',#45,1.);
#45 = DIRECTION('',(0.,0.,1.));
#46 = ORIENTED_EDGE('',*,*,#47,.F.);
#47 = EDGE_CURVE('',#24,#40,#48,.T.);
#48 = LINE('',#49,#50);
#49 = CARTESIAN_POINT('',(0.,0.,10.));
#50 = VECTOR('',#51,1.);
#51 = DIRECTION('',(0.,1.,0.));
#52 = PLANE('',#53);
#53 = AXIS2_PLACEMENT_3D('',#54,#55,#56);
#54 = CARTESIAN_POINT('',(0.,0.,0.));
#55 = DIRECTION('',(1.,0.,0.));
#56 = DIRECTION('',(0.,0.,1.));
#57 = ADVANCED_FACE('',(#58),#92,.T.);
#58 = FACE_BOUND('',#59,.T.);
#59 = EDGE_LOOP('',(#60,#70,#78,#86));
#60 = ORIENTED_EDGE('',*,*,#61,.F.);
#61 = EDGE_CURVE('',#62,#64,#66,.T.);
#62 = VERTEX_POINT('',#63);
#63 = CARTESIAN_POINT('',(60.,0.,0.));
#64 = VERTEX_POINT('',#65);
#65 = CARTESIAN_POINT('',(60.,0.,10.));
#66 = LINE('',#67,#68);
#67 = CARTESIAN_POINT('',(60.,0.,0.));
#68 = VECTOR('',#69,1.);
#69 = DIRECTION('',(0.,0.,1.));
#70 = ORIENTED_EDGE('',*,*,#71,.T.);
#71 = EDGE_CURVE('',#62,#72,#74,.T.);
#72 = VERTEX_POINT('',#73);
#73 = CARTESIAN_POINT('',(60.,20.,0.));
#74 = LINE('',#75,#76);
#75 = CARTESIAN_POINT('',(60.,0.,0.));
#76 = VECTOR('',#77,1.);
#77 = DIRECTION('',(0.,1.,0.));
#78 = ORIENTED_EDGE('',*,*,#79,.T.);
#79 = EDGE_CURVE('',#72,#80,#82,.T.);
#80 = VERTEX_POINT('',#81);
#81 = CARTESIAN_POINT('',(60.,20.,10.));
#82 = LINE('',#83,#84);
#83 = CARTESIAN_POINT('',(60.,20.,0.));
#84 = VECTOR('',#85,1.);
#85 = DIRECTION('',(0.,0.,1.));
#86 = ORIENTED_EDGE('',*,*,#87,.F.);
#87 = EDGE_CURVE('',#64,#80,#88,.T.);
#88 = LINE('',#89,#90);
#89 = CARTESIAN_POINT('',(60.,0.,10.));
#90 = VECTOR('',#91,1.);
#91 = DIRECTION('',(0.,1.,0.));
#92 = PLANE('',#93);
#93 = AXIS2_PLACEMENT_3D('',#94,#95,#96);
#94 = CARTESIAN_POINT('',(60.,0.,0.));
#95 = DIRECTION('',(1.,0.,0.));
#96 = DIRECTION('',(0.,0.,1.));
#97 = ADVANCED_FACE('',(#98),#114,.F.);
#98 = FACE_BOUND('',#99,.F.);
#99 = EDGE_LOOP('',(#100,#106,#107,#113));
#100 = ORIENTED_EDGE('',*,*,#101,.F.);
#101 = EDGE_CURVE('',#22,#62,#102,.T.);
#102 = LINE('',#103,#104);
#103 = CARTESIAN_POINT('',(0.,0.,0.));
#104 = VECTOR('',#105,1.);
#105 = DIRECTION('',(1.,0.,0.));
#106 = ORIENTED_EDGE('',*,*,#21,.T.);
#107 = ORIENTED_EDGE('',*,*,#108,.T.);
#108 = EDGE_CURVE('',#24,#64,#109,.T.);
#109 = LINE('',#110,#111);
#110 = CARTESIAN_POINT('',(0.,0.,10.));
#111 = VECTOR('',#112,1.);
#112 = DIRECTION('',(1.,0.,0.));
#113 = ORIENTED_EDGE('',*,*,#61,.F.);
#114 = PLANE('',#115);
#115 = AXIS2_PLACEMENT_3D('',#116,#117,#118);
#116 = CARTESIAN_POINT('',(0.,0.,0.));
#117 = DIRECTION('',(0.,1.,0.));
#118 = DIRECTION('',(0.,0.,1.));
#119 = ADVANCED_FACE('',(#120),#136,.T.);
#120 = FACE_BOUND('',#121,.T.);
#121 = EDGE_LOOP('',(#122,#128,#129,#135));
#122 = ORIENTED_EDGE('',*,*,#123,.F.);
#123 = EDGE_CURVE('',#32,#72,#124,.T.);
#124 = LINE('',#125,#126);
#125 = CARTESIAN_POINT('',(0.,20.,0.));
#126 = VECTOR('',#127,1.);
#127 = DIRECTION('',(1.,0.,0.));
#128 = ORIENTED_EDGE('',*,*,#39,.T.);
#129 = ORIENTED_EDGE('',*,*,#130,.T.);
#130 = EDGE_CURVE('',#40,#80,#131,.T.);
#131 = LINE('',#132,#133);
#132 = CARTESIAN_POINT('',(0.,20.,10.));
#133 = VECTOR('',#134,1.);
#134 = DIRECTION('',(1.,0.,0.));
#135 = ORIENTED_EDGE('',*,*,#79,.F.);
#136 = PLANE('',#137);
#137 = AXIS2_PLACEMENT_3D('',#138,#139,#140);
#138 = CARTESIAN_POINT('',(0.,20.,0.));
#139 = DIRECTION('',(0.,1.,0.));
#140 = DIRECTION('',(0.,0.,1.));
#141 = ADVANCED_FACE('',(#142),#148,.F.);
#142 = FACE_BOUND('',#143,.F.);
#143 = EDGE_LOOP('',(#144,#145,#146,#147));
#144 = ORIENTED_EDGE('',*,*,#31,.F.);
#145 = ORIENTED_EDGE('',*,*,#101,.T.);
#146 = ORIENTED_EDGE('',*,*,#71,.T.);
#147 = ORIENTED_EDGE('',*,*,#123,.F.);
#148 = PLANE('',#149);
#149 = AXIS2_PLACEMENT_3D('',#150,#151,#152);
#150 = CARTESIAN_POINT('',(0.,0.,0.));
#151 = DIRECTION('',(0.,0.,1.));
#152 = DIRECTION('',(1.,0.,0.));
#153 = ADVANCED_FACE('',(#154),#160,.T.);
#154 = FACE_BOUND('',#155,.T.);
#155 = EDGE_LOOP('',(#156,#157,#158,#159));
#156 = ORIENTED_EDGE('',*,*,#47,.F.);
#157 = ORIENTED_EDGE('',*,*,#108,.T.);
#158 = ORIENTED_EDGE('',*,*,#87,.T.);
#159 = ORIENTED_EDGE('',*,*,#130,.F.);
#160 = PLANE('',#161);
#161 = AXIS2_PLACEMENT_3D('',#162,#163,#164);
#162 = CARTESIAN_POINT('',(0.,0.,10.));
#163 = DIRECTION('',(0.,0.,1.));
#164 = DIRECTION('',(1.,0.,0.));
#165 = ( GEOMETRIC_REPRESENTATION_CONTEXT(3)
GLOBAL_UNCERTAINTY_ASSIGNED_CONTEXT((#169)) GLOBAL_UNIT_ASSIGNED_CONTEXT
((#166,#167,#168)) REPRESENTATION_CONTEXT('Context #1',
'3D Context with UNIT and UNCERTAINTY') );Read top down: a three-dimensional coordinate space, measured in millimetres, radians and steradians, in which two points closer than \(10^{-7}\) mm are the same point.
6.1 Representations and their contexts
The word representation is Part 43’s, and it is worth a moment because it organises half the file. A representation is a set of representation items together with a representation context that says how to interpret them. #10 is a representation: its items are #11 (an axis placement) and #15 (a solid), and its context is #165. Every point, curve, surface, face and solid in the file is a representation item, and every one belongs to some representation, and every representation has exactly one context.
The context is where units live. It is shared: in a single-part file one context carries the units and every geometric representation points at it — though the file may still hold a unitless 2D context per pcurve, as Chapter 13 shows. In an assembly file there may be several — OCCT writes one per product, all identical — and each representation points at its own. A reader that assumes one context per file will be right most of the time and wrong in ways that are hard to notice.
6.2 The context record
#165 is a complex instance of four types, and Chapter 4 explained why: representation_ has no supertype constraint, so any combination of its subtypes is legal, and this one is three at once.
REPRESENTATION_— the root, with an identifier and a free-text type. Both strings are the writer’s choice and mean nothing to a reader.CONTEXT('Context #1','3D Context with UNIT and UNCERTAINTY') GEOMETRIC_— this context is for geometry, in three dimensions. Two-dimensional contexts,REPRESENTATION_ CONTEXT(3) (2), appear in files that carry drawing views or the 2D parameter-space curves of Chapter 13.GLOBAL_— the units in force for every item in this context.UNIT_ ASSIGNED_ CONTEXT((#166,#167,#168)) GLOBAL_— the tolerance in force.UNCERTAINTY_ ASSIGNED_ CONTEXT((#169))
AP203’s first edition is the strictest: the unit set must hold exactly three units, one length, one plane angle and one solid angle. AP214 requires exactly one length unit and exactly one plane angle unit and says nothing about solid angle; AP203 second edition and AP242 state no rule at all. Nothing in a mechanical file ever measures a solid angle, but the oldest and most widely implemented of the three demanded one, so exporters emit a steradian everywhere and you will see #168 in nearly every file.
6.3 The millimetre
#166 = ( LENGTH_UNIT() NAMED_UNIT(*) SI_UNIT(.MILLI.,.METRE.) );Three blocks, alphabetical. LENGTH_ declares no attributes and says only this measures length. NAMED_ carries the derived dimensions. SI_ gives the prefix and the base unit. A metre would be SI_; a micron SI_. The radian and steradian at #167 and #168 follow the same pattern with $ for no prefix, and with PLANE_ and SOLID_ in place of LENGTH_.
This exact record — the millimetre as a three-way complex instance — is probably the most frequently written line in all of STEP.
6.4 Inch files
Imperial units cannot be spelled with an SI prefix and name, so an inch is a conversion-based unit: a named unit defined as a multiple of another unit. The block, exported by the same OCCT build with its output unit set to inches:
#166 = ( CONVERSION_BASED_UNIT('INCH',#168) LENGTH_UNIT() NAMED_UNIT(#167) );
#167 = DIMENSIONAL_EXPONENTS(1.,0.,0.,0.,0.,0.,0.);
#168 = LENGTH_MEASURE_WITH_UNIT(25.4,#169);
#169 = ( LENGTH_UNIT() NAMED_UNIT(*) SI_UNIT(.MILLI.,.METRE.) );
#172 = UNCERTAINTY_MEASURE_WITH_UNIT(LENGTH_MEASURE(3.937007874016E-09),#166,
'distance_accuracy_value','confusion accuracy');#166 is still a length unit and still a named unit, but SI_ has been replaced by CONVERSION_, which carries a name and a conversion_. Because the blocks are alphabetical it now sorts first. The factor, #168, is a measure with unit: 25.4 of unit #169. And #169 is the millimetre. So an inch file contains the millimetre after all — as the thing the inch is defined in terms of — and every coordinate in the file is then in inches: the block’s far corner is at (2.362204724409,0.787401574803,0.393700787402), and the uncertainty has been converted too, to \(3.9 \times 10^{-9}\) inches.
Three details. First, NAMED_ is an explicit reference where the SI record had *. An SI unit’s dimensions are always derived from its name, so that slot is *. For a conversion-based unit AP203 and AP242 require the exponents to be written out and to agree with the factor’s unit; AP214 edition 3 derives them instead, so a conversion-based unit written to that edition carries NAMED_ and no DIMENSIONAL_ record at all. This file, an older AP214, writes them out. Here DIMENSIONAL_ says length\(^{1}\) mass\(^{0}\) time\(^{0}\) current\(^{0}\) temperature\(^{0}\) substance\(^{0}\) luminosity\(^{0}\) — a length. Second, the string 'INCH' is a label. What makes it an inch is the 25.4. A reader that keys on the name will meet 'inch', 'IN' and 'Inch' before long; the factor is the reliable part. Third — and this is a real defect in a widely used exporter — the 25.4 in #168 is written bare. Chapter 4’s rule says a SELECT-typed value that is not an entity must be wrapped, and the uncertainty record two lines below wraps its value correctly as LENGTH_; the conversion factor should read LENGTH_. Every mainstream reader accepts the bare form, which is why it has never been fixed, and it is a fair specimen of the gap between the standard and the files.
Angles are treated the same way. A file that measures angles in degrees carries (this excerpt written to the same pattern rather than exported)
#900 = ( CONVERSION_BASED_UNIT('DEGREE',#901) NAMED_UNIT(#902)
PLANE_ANGLE_UNIT() );
#901 = PLANE_ANGLE_MEASURE_WITH_UNIT(PLANE_ANGLE_MEASURE(0.01745329252),#903);
#902 = DIMENSIONAL_EXPONENTS(0.,0.,0.,0.,0.,0.,0.);
#903 = ( NAMED_UNIT(*) PLANE_ANGLE_UNIT() SI_UNIT($,.RADIAN.) );— a degree is 0.0174533 radians, and an angle is dimensionless, so every exponent is zero.
6.5 Uncertainty
#169 = UNCERTAINTY_MEASURE_WITH_UNIT(LENGTH_MEASURE(1.E-07),#166,
'distance_accuracy_value','confusion accuracy');Referred to above: 1 record from block.step
#166 = ( LENGTH_UNIT() NAMED_UNIT(*) SI_UNIT(.MILLI.,.METRE.) );Four attributes: a value (wrapped, because measure_ is a SELECT), a unit (bare, because it is an entity), a name, and a description. The name is the important one. 'distance_ is the string the recommended practices call for, and it means: two points closer together than this value are to be treated as coincident. Here that is one ten-millionth of a millimetre.
A boundary representation says that a solid’s faces meet along shared edges and its edges meet at shared vertices. But the faces are defined by surfaces — planes, cylinders, splines — and the edges by curves, and those are computed in floating point. Where a cylinder meets a plane, the curve of intersection does not lie exactly on either; it lies within some small distance of both. Whether a shell is “closed” is therefore a question about a threshold: are the gaps smaller than the tolerance? Every geometric kernel has such a threshold, and they differ — \(10^{-7}\) in Open CASCADE, \(10^{-6}\) or \(10^{-8}\) elsewhere, sometimes scaled to the model’s size. The file records the writer’s value so that a reader can know how tightly the geometry was made to fit. If the reader’s kernel is stricter, gaps that were invisible at export become holes at import, and the solid falls apart into a surface model. Much of the “healing” that STEP importers do is repairing exactly that.
The uncertainty is what makes the same file behave differently in different tools. A 'confusion accuracy' of \(10^{-7}\) mm from one kernel and \(10^{-4}\) mm from another describe geometry fitted to very different thresholds, and the reader that ignores this value is the one whose imports mysteriously fail. The value is a declaration, not a measurement: OCCT, for one, can be set to write its default precision, a user-chosen value, or the smallest, average or largest tolerance among the shape’s sub-shapes, and its reader can be told to ignore the file’s value and use its own. It says nothing about topology either: vertices are shared by reference, and nothing in a file is merged because its coordinates are close.
6.6 Derived units
Length, angle and solid angle cover geometry. Properties such as area, volume and mass need units that are products of the base ones, and Part 41 provides DERIVED_:
#300 = DERIVED_UNIT((#301));
#301 = DERIVED_UNIT_ELEMENT(#166,3.);Referred to above: 1 record from block.step
#166 = ( LENGTH_UNIT() NAMED_UNIT(*) SI_UNIT(.MILLI.,.METRE.) );#300 is “millimetres to the power three” — a cubic millimetre — built from one element: the length unit #166 raised to the exponent 3.. An area would use 2.; a density would combine a mass unit with exponent 1. and a length unit with exponent -3.. These appear with validation properties in Chapter 15 and almost nowhere else.
6.7 Contexts in assemblies
The clamp assembly of Chapter 8 has three geometric contexts, one per product, all textually identical to #165. Each product’s shape representation points at its own. One context for the whole file is not even legal here: the transformation record that places a component requires its two representations to sit in different context records, so the assembly’s context cannot also be a component’s. Writing one per product, as this exporter does, is the simplest way to satisfy that. It has a consequence that is easy to state and easy to forget: units are a property of the representation, not of the file. A file may, in principle, hold one part in millimetres and another in inches, each in its own context, and an assembly that places both. Readers that read the first context they find and apply it to everything will get the second part wrong by a factor of 25.4. Follow the reference from each representation to its context; never cache “the” unit.
Units live in the representation context, which every geometric representation references. A geometric context carries a length unit and a plane angle unit — required by AP214, conventional elsewhere — and by convention a solid angle unit too; each is a complex instance. SI units derive their dimensions; conversion-based units (inch, degree) define themselves as a multiple of another unit — this inch file carries 25.4 millimetres, another could carry 0.0254 metres — and whether their dimensions are written out or derived depends on the schema edition. The uncertainty is the writing kernel’s coincidence tolerance, named 'distance_: a declaration of the writer’s threshold, not a measurement of the geometry. A file can have several contexts; units belong to representations, not files.