FEAT - FOUNDRY: activate sector workspace
This commit is contained in:
@@ -84,6 +84,80 @@ export function localSectorAt(point, definition) {
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Projects a WGS84 surface position onto the fixed origin's ENU tangent
|
||||
* plane. This mirrors the renderer's analytic sector picking: the target
|
||||
* surface normal is intersected with the origin plane before addressing.
|
||||
*/
|
||||
export function geodeticToLocalGridPlane(point, definition) {
|
||||
const latitude = clamp(finite(point?.latitude, 0), -90, 90) * Math.PI / 180;
|
||||
const longitude = normalizeLongitudeDegrees(finite(point?.longitude, 0)) * Math.PI / 180;
|
||||
const originLatitude = clamp(finite(definition?.originLatitude, 0), -90, 90) * Math.PI / 180;
|
||||
const originLongitude = normalizeLongitudeDegrees(finite(definition?.originLongitude, 0)) * Math.PI / 180;
|
||||
|
||||
const surfaceCartesian = (lat, lon) => {
|
||||
const sineLatitude = Math.sin(lat);
|
||||
const cosineLatitude = Math.cos(lat);
|
||||
const primeVerticalRadius = WGS84_EQUATORIAL_RADIUS_METERS
|
||||
/ Math.sqrt(1 - WGS84_ECCENTRICITY_SQUARED * sineLatitude ** 2);
|
||||
return {
|
||||
x: primeVerticalRadius * cosineLatitude * Math.cos(lon),
|
||||
y: primeVerticalRadius * cosineLatitude * Math.sin(lon),
|
||||
z: primeVerticalRadius * (1 - WGS84_ECCENTRICITY_SQUARED) * sineLatitude,
|
||||
};
|
||||
};
|
||||
|
||||
const origin = surfaceCartesian(originLatitude, originLongitude);
|
||||
const target = surfaceCartesian(latitude, longitude);
|
||||
const offset = {
|
||||
x: target.x - origin.x,
|
||||
y: target.y - origin.y,
|
||||
z: target.z - origin.z,
|
||||
};
|
||||
const east = {
|
||||
x: -Math.sin(originLongitude),
|
||||
y: Math.cos(originLongitude),
|
||||
z: 0,
|
||||
};
|
||||
const north = {
|
||||
x: -Math.sin(originLatitude) * Math.cos(originLongitude),
|
||||
y: -Math.sin(originLatitude) * Math.sin(originLongitude),
|
||||
z: Math.cos(originLatitude),
|
||||
};
|
||||
const up = {
|
||||
x: Math.cos(originLatitude) * Math.cos(originLongitude),
|
||||
y: Math.cos(originLatitude) * Math.sin(originLongitude),
|
||||
z: Math.sin(originLatitude),
|
||||
};
|
||||
const targetNormal = {
|
||||
x: Math.cos(latitude) * Math.cos(longitude),
|
||||
y: Math.cos(latitude) * Math.sin(longitude),
|
||||
z: Math.sin(latitude),
|
||||
};
|
||||
const dot = (left, right) => left.x * right.x + left.y * right.y + left.z * right.z;
|
||||
const localSurface = {
|
||||
eastMeters: dot(offset, east),
|
||||
northMeters: dot(offset, north),
|
||||
upMeters: dot(offset, up),
|
||||
};
|
||||
const localNormal = {
|
||||
east: dot(targetNormal, east),
|
||||
north: dot(targetNormal, north),
|
||||
up: dot(targetNormal, up),
|
||||
};
|
||||
const normalScale = Math.abs(localNormal.up) > EPSILON
|
||||
? -localSurface.upMeters / localNormal.up
|
||||
: 0;
|
||||
return {
|
||||
eastMeters: localSurface.eastMeters + localNormal.east * normalScale,
|
||||
northMeters: localSurface.northMeters + localNormal.north * normalScale,
|
||||
};
|
||||
}
|
||||
|
||||
export function localSectorAtGeodetic(point, definition) {
|
||||
return localSectorAt(geodeticToLocalGridPlane(point, definition), definition);
|
||||
}
|
||||
|
||||
export function localSectorBounds(address, stepMeters) {
|
||||
const step = Math.max(EPSILON, finite(stepMeters, 1));
|
||||
return {
|
||||
|
||||
Reference in New Issue
Block a user