Measure
Positions, lengths, distances and angles of elements of the geometry, as the Measure plugin of react-cad shows them.
Objects
Measure
const Measure: {
areParallel(vec1, vec2): boolean;
arePerpendicular(vec1, vec2): boolean;
calculateArcPlane(arc, plane): MeasureResult[];
calculateLineLine(first, second): MeasureResult[];
calculateLinePlane(line, plane): MeasureResult[];
calculateMeasures(objects, drawingId): MeasureResult[];
calculatePlanePlane(plane1, plane2): MeasureResult[];
calculatePointLine(point, line): MeasureResult[];
calculatePointPlane(point, plane): MeasureResult[];
calculatePointPoint(point1, point2): MeasureResult[];
degrees(radians): number;
getArcPlaneMPoints(arcCenter, arcNormal, pointOnPlane, planeNormal): [Vector3, Vector3] | [undefined, undefined];
getInfo(objects, drawingId): MeasureResult[];
getLineLineMDirs(start1Pos, end1Pos, start2Pos, end2Pos): Vector3[];
getLineLineMPoints(start1Pos, end1Pos, start2Pos, end2Pos): [Vector3, Vector3] | [undefined, undefined];
getLinePlaneMPoints(startPos, endPos, pointOnPlane, normal): [Vector3, Vector3] | [undefined, undefined];
getPlanePlaneMDirs(normal1, normal2): Vector3[] | undefined[];
getPlanePlaneMPoints(pointOnPlane1, normal1, pointOnPlane2, normal2): [Vector3, Vector3] | [undefined, undefined];
getPointLineMPoints(pointsPos, startPos, endPos): [Vector3, Vector3];
getPointPlaneMPoints(pointPos, pointOnPlane, normal): [Vector3, Vector3];
transform(items, drawingId): ProductElement[];
};
Measures elements of the geometry: positions, lengths, radii, distances and angles, in world coordinates.
Measure.getInfo measures elements each on their own (a line's length, a cylinder's radius and axis, …),
Measure.calculateMeasures measures between two (distance, angles). Both take the elements as a selector
holds them, with their products (ProductElement), and place them in the world first. The functions that
take positions and elements directly (calculatePointPoint, …) expect world coordinates: see
Measure.transform. Lengths are in the model's units, angles in degrees.
Type Declaration
| Name | Type | Description |
|---|---|---|
areParallel() | (vec1, vec2) => boolean | Returns whether two vectors are parallel: the length of their cross product is below 0.001, so it depends on their lengths as well; normalize them for directions. |
arePerpendicular() | (vec1, vec2) => boolean | Returns whether two vectors are perpendicular (within 0.001). |
calculateArcPlane() | (arc, plane) => MeasureResult[] | Measures the distance of an arc's center from a plane, if the arc lies parallel to it. |
calculateLineLine() | (first, second) => MeasureResult[] | Measures between two lines: their distance, if they are parallel and apart, and the two angles between them (Angle1, and Angle2, 180° minus it). |
calculateLinePlane() | (line, plane) => MeasureResult[] | Measures the distance of a line from a plane, if it is parallel to it. |
calculateMeasures() | (objects, drawingId) => MeasureResult[] | Measures between the first two elements, in world coordinates: the distance of points, lines, planes, arcs and circles (their centers), and the angles of lines and of planes. For other pairs it returns what Measure.getInfo returns for the elements. Needs two elements; for a point, a line, an arc, a circle or a plane as the first, it throws with fewer. |
calculatePlanePlane() | (plane1, plane2) => MeasureResult[] | Measures between two planes: their distance if they are parallel, their angle if they are not. |
calculatePointLine() | (point, line) => MeasureResult[] | Measures the distance of a point from a line (the line extended beyond its ends). |
calculatePointPlane() | (point, plane) => MeasureResult[] | Measures the distance of a point from a plane. |
calculatePointPoint() | (point1, point2) => MeasureResult[] | Measures between two positions: the distance, and its parts along x, y and z (dx, dy, dz). |
degrees() | (radians) => number | Converts radians to degrees. |
getArcPlaneMPoints() | ( arcCenter, arcNormal, pointOnPlane, planeNormal ) => [Vector3, Vector3] | [undefined, undefined] | Returns the ends of an arc center's distance from a plane parallel to the arc; [undefined, undefined] otherwise. |
getInfo() | (objects, drawingId) => MeasureResult[] | Measures elements each on their own, in world coordinates: a point's position, a line's length, an arc's center, normal and radius, a plane's normal, a cylinder's or cone's axis, radii and height, a sphere's radius. |
getLineLineMDirs() | ( start1Pos, end1Pos, start2Pos, end2Pos ) => Vector3[] | Returns the directions of two lines, each from its start to its end. |
getLineLineMPoints() | ( start1Pos, end1Pos, start2Pos, end2Pos ) => [Vector3, Vector3] | [undefined, undefined] | Returns the ends of the distance of two parallel lines that are apart; [undefined, undefined] otherwise. |
getLinePlaneMPoints() | ( startPos, endPos, pointOnPlane, normal ) => [Vector3, Vector3] | [undefined, undefined] | Returns the ends of a line's distance from a plane it is parallel to; [undefined, undefined] otherwise. |
getPlanePlaneMDirs() | (normal1, normal2) => Vector3[] | undefined[] | Returns the directions whose angle is the angle of two planes that are not parallel (at most 90° apart); [undefined, undefined] for parallel planes. |
getPlanePlaneMPoints() | ( pointOnPlane1, normal1, pointOnPlane2, normal2 ) => [Vector3, Vector3] | [undefined, undefined] | Returns the ends of the distance of two parallel planes; [undefined, undefined] otherwise. |
getPointLineMPoints() | ( pointsPos, startPos, endPos ) => [Vector3, Vector3] | Returns the ends of a point's distance from a line: the point, and the nearest point of the (extended) line. |
getPointPlaneMPoints() | ( pointPos, pointOnPlane, normal ) => [Vector3, Vector3] | Returns the ends of a point's distance from a plane: the point, and the nearest point of the plane. |
transform() | (items, drawingId) => ProductElement[] | Returns copies of elements placed in the world: their positions and directions transformed by their products. Points, lines, planes, cylinders, cones, arcs and circles are transformed; other elements are copied as they are. The elements themselves are not changed. |
Example
import { DrawingID, LinearMeasureData, Measure, MeasureResultType, ProductElement } from '@buerli.io/core'
import { useDrawing } from '@buerli.io/react'
// The distance of the two elements a selector holds, as the user picks them
function Distance({ drawingId, selectorId }: { drawingId: DrawingID; selectorId: string }) {
const items = useDrawing(drawingId, drawing => drawing.selection.refs[selectorId]?.items)
if (items?.length !== 2) return null
const elements = items.map(item => item.data as ProductElement)
const results = Measure.calculateMeasures(elements, drawingId)
const distance = results.find(result => result.type === MeasureResultType.DISTANCE && result.measureData)
return distance ? <p>Distance: {(distance.measureData as LinearMeasureData).value.toFixed(2)}</p> : null
}
Types
AngularMeasureData
type AngularMeasureData = {
center: THREE.Vector3;
dir1: THREE.Vector3;
dir2: THREE.Vector3;
value: number;
};
An angle: the data of a MeasureResult of type ANGLE.
Properties
LinearMeasureData
type LinearMeasureData = {
end: THREE.Vector3;
start: THREE.Vector3;
value: number;
};
A length or a distance: the data of a MeasureResult of type DISTANCE.
Properties
| Property | Type | Description |
|---|---|---|
end | THREE.Vector3 | Where it is measured to. |
start | THREE.Vector3 | Where it is measured from, in world coordinates (to draw it). |
value | number | The length. |
MeasureResult
type MeasureResult = {
description: string;
measureData?: | ValueMeasureData
| LinearMeasureData
| AngularMeasureData
| PositionMeasureData
| VectorMeasureData;
type: MeasureResultType;
};
One measure of elements of the geometry, as Measure returns them: what it is, and its data.
Measure has an example that reads one.
Properties
| Property | Type | Description |
|---|---|---|
description | string | What is measured, such as Distance, Line length or Cylinder radius. |
measureData? | | ValueMeasureData | LinearMeasureData | AngularMeasureData | PositionMeasureData | VectorMeasureData | The measure; none when there is nothing to measure, such as the distance of lines that are not parallel. |
type | MeasureResultType | What kind of measure it is, which tells the kind of measureData. |
MeasureResultType
What a MeasureResult measures, and so which data it has.
Measure has an example that tells results apart by it.
Enumeration Members
| Enumeration Member | Value | Description |
|---|---|---|
ANGLE | "angular" | An angle, AngularMeasureData. |
DISTANCE | "linear" | A length or a distance, LinearMeasureData. |
NONE | "none" | Nothing to measure; the result has no data. |
POSITION | "position" | A position, PositionMeasureData. |
VALUE | "value" | A number, ValueMeasureData. |
VECTOR | "vector" | A direction, VectorMeasureData. |
PositionMeasureData
type PositionMeasureData = {
value: THREE.Vector3;
};
A position: the data of a MeasureResult of type POSITION.
Properties
| Property | Type | Description |
|---|---|---|
value | THREE.Vector3 | The position, in world coordinates. |
ValueMeasureData
type ValueMeasureData = {
value: number;
};
A number, such as a sphere's radius: the data of a MeasureResult of type VALUE.
Properties
| Property | Type | Description |
|---|---|---|
value | number | The number. |
VectorMeasureData
type VectorMeasureData = {
end: THREE.Vector3;
start: THREE.Vector3;
value: THREE.Vector3;
};
A direction, such as an axis or a normal: the data of a MeasureResult of type VECTOR.
Properties
| Property | Type | Description |
|---|---|---|
end | THREE.Vector3 | Where it is drawn to. |
start | THREE.Vector3 | Where it is drawn from, in world coordinates. |
value | THREE.Vector3 | The direction. |