viewer-components-react icon indicating copy to clipboard operation
viewer-components-react copied to clipboard

Add Bearing in Measure Distance Tool.

Open mathieu-fournier opened this issue 11 months ago • 4 comments

Improvement in Measure Distance Tool. Add the Bearing direction of the Measurement : Image

For more information on Bearing see : https://github.com/iTwin/itwinjs-core/issues/6907

mathieu-fournier avatar Apr 15 '25 17:04 mathieu-fournier

@mathieu-fournier

We can add logic into the measureDistanceTool to add a line for Bearing. By default, it will try to get a format associated with the KoQ RoadRailUnits.Bearing through the formatsProvider, like so:

const formatProps = await IModelApp.FormatsProvider.getFormat("RoadRailUnits.Bearing")

Applications can supply a FormatsProvider to IModelApp, one that has a presentation format for RRU.Bearing always available, or rely on registering a SchemaFormatsProvider, and hope the iModel contains the RoadRailUnits schema.

That leads me to a question: What if the format for RRU.Bearing does not exist? Do you want to always show the Bearing measurement, or is this application/domain specific? Should there be a default format the measure tool should fallback on, that is available at the core level, or just within the measure tools?

EDIT: The tool doesn't have to rely on schemas coming from just iModels, registering a formatsProvider that always has a key and value pair for RRU.Bearing is possible.

hl662 avatar May 13 '25 19:05 hl662

I'll also add that the persistenceUnit this measurement will look to use is unit.HORIZONTAL_DIR_RAD, not unit.RAD like the schema for RoadRailUnits shows in the link for the comment above. Since Units.Horizontal_DIR_RAD is a new unit, it's not guaranteed to exist, so we'll want to think about situations where the format and/or the persistenceUnit wasn't found via the formatsProvider or unitsProvider of ImodelApp

hl662 avatar May 13 '25 19:05 hl662

If there is no Bearing format, I suggest to show the angle in radians. Even better would be to not display Bearings at all if the format does not exist.

mathieu-fournier avatar May 13 '25 20:05 mathieu-fournier

Understood.

Implementation-specifics for this task will involve editing DistanceMeasurement getDataForMeasurementWidgetInternal() to calculate the bearing, apply a bearing FormatterSpec to generate a formatted string, and push an entry to the returned MeasurementWidgetData

Further information on how to calculate a value for bearing, to apply formatting on:

Bearing is a planar angle from "north" measured in a "west" (counterclockwise) or "east" (clockwise) direction. on lines 477-482 are quantities derived from a line segment. It should be possible to define a bearing for the line segment (more specifically its vector) if we know the vector that "north" represents and the plane in which to measure the bearing angle. This boils down to the measurement of the angle between two vectors, and core-geometry has methods for that, e.g. Vector3d.planarAngleTo.

hl662 avatar May 13 '25 21:05 hl662

Image @mathieu-fournier is this a correct bearing value? I calculated the bearing in this code snippet of a WIP draft PR

hl662 avatar Jun 03 '25 21:06 hl662

is this a correct bearing value?

@hl662 I looked at the snippet an it looks fine to me. Does the value works in all 4 quadrants and in all 4 exact cardinal directions ?

mathieu-fournier avatar Jun 04 '25 14:06 mathieu-fournier

Oops, the code used absolute values for dx and dy, so it was buggy. After fixing it, it works in all 4 quadrants Image

Image

Image

Image

I couldn't draw an exact distance that goes in any of the cardinal directions, so I hard coded 0, pi, 2 pi to the result of the calculations and it formats it well I believe:

Below is when bearing is 0: Image

Below is when bearing is pi:

Image

hl662 avatar Jun 04 '25 15:06 hl662