6.4 Distances
ASAM OpenSCENARIO interprets distances in special ways. To properly use instances of Action
and Condition
, it is important to understand distance interpretation.
Depending on the use case, a distance may be specified between:

Two points

A point and an
Entity
(with or without bounding box considerations) 
Two entities (with or without bounding box considerations)
The general term point used in this chapter may be replaced with the ASAM OpenSCENARIO specific term position. Within the scope of this chapter, both terms can be used interchangeably. 
Distances in ASAM OpenSCENARIO may be measured in two ways:

From a local coordinate system, with lateral and longitudinal distance in an
Entity
, road, lane, or trajectory coordinate system 
In absolute context, that is Euclidean distance
ASAM OpenSCENARIO assumes distances to be greater than equal to zero, (ℝ^{+}_{0}).
6.4.1 Visualization
If not otherwise stated, the threedimensional Euclidean space (ℝ^{3}) is used for distance measurement. In some cases and for better visualization, a twodimensional space is used (ℝ^{2}). In these cases, generalization for ℝ^{3} is provided.
For convenience, only one direction of travel is shown when visualizing a road, as shown in Figure 8.
6.4.2 Referring to distances in ASAM OpenSCENARIO
In ASAM OpenSCENARIO, lateral and longitudinal distance depends on the type of referential, for example Entity
, road, lane, or trajectory. Euclidean distance is measured in a global context.
6.4.3 Euclidean distance
Euclidean distance between two points in Euclidean space is the length of a line segment between those two points, as shown in Figure 9. It is unambiguously defined in ℝ^{3}, independently from the coordinate system that describes the coordinates.
6.4.4 Distances in an entity coordinate system
Given two points A = (X_{A} , Y_{A} , Z_{A}) and B = (X_{B} , Y_{B} , Z_{B}) in the coordinates of a specific Entity
, the definition in ASAM OpenSCENARIO is:

Longitudinal Entity distance  (dX_{AB}): X_{B}  X_{A} 

Lateral Entity distance  (dY_{AB}): Y_{B}  Y_{A} 
6.4.5 Distances in road coordinates
Given two points in road coordinates A = (s_{A} , t_{A} , h_{A}) and B = (s_{B} , t_{B} , h_{B}), the definition in ASAM OpenSCENARIO is:

Longitudinal road distance: ds_{AB}: s_{B}  s_{A}

Lateral road distance: dt_{AB}: t_{B}  t_{A}
6.4.6 Lane distance and trajectory distance
Distances based on the lane or trajectory referentials are measured using the same methods as distances measured in the road referential.

Distances measured in the lane referential use the lane center as a reference line, rather than the road reference line.

Distances measured in the trajectory referential use the trajectory as a reference line, rather than the road reference line.
Trajectories do not define a road plane and thus no lateral direction. Trajectories shall be projected onto a road or plane, depending on the definition for measuring unambiguous lateral trajectory distances. 
6.4.7 Involving an entity in a distance calculation
In addition to distances between two points, ASAM OpenSCENARIO also support distance measurement between two entities or between an entity and a point. In both cases, it is important to identify the two points of interest and apply the distance concepts introduced in this chapter.
Identifying the point of interest for an Entity
depends on the value of the Boolean attribute freeSpace
. It determines whether the entities bounding box shall be taken into consideration (freeSpace = true
), or shall not be taken into consideration (freeSpace = false
).
6.4.7.1 freeSpace = false
In this case, the bounding boxes of the entity shall not be considered. The point of the entity used to calculate the distance is the entity’s origin. That means:

The distance between point P and
Entity
E is the distance between point P andEntity
E’s origin (E0), as shown in Figure 12.
In this case, the bounding boxes of the Entity
shall be considered. Which point is chosen depends on the desired distance type.

The distance between
Entity
E andEntity
F is the distance between their origins (E0, F0), as shown in Figure 13.
6.4.7.2 freeSpace = true
For distances between entities and reference points:

In the
Entity
referential, if the desired distance is the Euclidean distance, then the point of interest is the point on the bounding box of theEntity
which yields the lowest distance value to the reference point. 
If the desired distance is longitudinal, then the point of interest is the point on the bounding box of the
Entity
that yields the lowest longitudinal distance to the reference point. 
If the desired distance is lateral, then the point of interest is the point on the bounding box of the
Entity
that yields the lowest lateral distance to the reference point.
If freeSpace = true , the distance between an Entity and a point on or in its bounding box is zero.

For distances between entities:

In the
Entity
referential, if the desired distance is the Euclidean distance, then the points of interest are the two points on the entities' bounding boxes that yield the lowest distance. 
If the desired distance is longitudinal, then the points of interest are the two points on the entities' bounding boxes that yield the lowest longitudinal distance.

If the desired distance is lateral, then the points of interest are the two points on the entities' bounding boxes that yield the lowest lateral distance.
If freeSpace = true , the distance between two entities whose bounding boxes intersect is zero.

6.4.8 Guideline for positions on different roads
6.4.8.1 Longitudinal distance
6.4.8.1.1 Road coordinate system
The longitudinal distance can only be calculated when the path between start and target positions forms an unambiguous chain of consecutive road reference lines (saxes). In the case of ambiguity, a helping route can be defined so that both start and target positions are found on the same route (see for more the section Section 6.4.8.3, “Helping route”).
When calculating the longitudinal distance, breaks of road reference lines (also known as saxes) of directly connected roads do not affect the result.
The longitudinal distance is calculated as a sum of lengths of segments along the chained road saxes between projections of start and target positions on respective saxes.
6.4.8.1.2 Lane coordinate system
The longitudinal distance can only be calculated when the path between start and target positions forms an unambiguous and continuous chain of consecutive lane center lines (also known as lane saxes). In the case of ambiguity, a helping route can be defined so that both start and target positions can be found on the same route (see for more the "Helping route" section).
The longitudinal distance is calculated as a sum of lengths of segments along the chained lane saxes between projections of start and target positions on respective saxes.
6.4.8.1.3 Trajectory coordinate system
The longitudinal distance is calculated as a sum of lengths of segments along the trajectory’s saxis between projections of start and target positions on the saxis. In the case, a normal being conducted to the trajectory’s saxis from the start or/and the target position does not intersect the saxis, the remaining space before the beginning or/and after the ending of the trajectory’s saxis is not included in the result and therefore considered as inaccuracy of calculations.
6.4.8.2 Lateral distance
6.4.8.2.1 Road coordinate system
The lateral distance can only be calculated when the path between start and target positions forms an unambiguous chain of consecutive road reference lines (also known as saxes). In the case of ambiguity, a helping route can be defined so that both start and target positions can be found on the same route (see for more the "Helping route" section).
In the case, reference lines of connected roads along the chain are not contiguous, the lateral distance is not meaningful and therefore undefined.
The lateral distance is calculated with a method that depends on the case:

as the modulus of the difference between tcoordinates of the start and target positions on respective road taxes if respective road saxes are headed in the same direction;

as the modulus of the sum of tcoordinates of the start and target positions on respective road taxes if respective road saxes are headed in opposite directions.
6.4.8.2.3 Trajectory coordinate system
The lateral distance is calculated as the modulus of the difference between tcoordinates of the start and target positions on respective trajectory taxes. In the case, a normal being conducted to the trajectory’s saxis from the start or/and the target position does not intersect the saxis, the lateral distance is undefined.
6.4.8.3 Helping route
The helping route can be either a one which is assigned to the acting or triggering Entity within the scenario or a one which is calculated by a simulator. The preferred RoutingAlgorithm
can be specified by means of several properties:

assignedRoute
: Use the route which has already been assigned to the entity at the start position at the point in time when the distance shall be calculated. 
fastest
: Calculate the route with the shortest travelling time between the start and target positions. 
leastIntersections
: Calculate the route with as few junctions as possible between the start and target positions. 
undefined
: It is up to the simulator how to calculate the route between the start and target positions. 
shortest
: Calculate the route with the shortest path between the start and target positions.
It must be noted, in the case of complex road networks, the calculation of the helping route might not give a single result, that might lead to an unexpected distance looked for.