diagonal: AABB Diagonal Vector Calculation
Extent Measurement for Bounding Box Dimensions
The AABB diagonal function computes the dimensional extent of an axis-aligned bounding box along each coordinate axis. This operation determines the width, height, and depth of the rectangular volume.
Given an AABB with bounds , the diagonal vector is calculated as:
The absolute value ensures positive dimensions regardless of coordinate system orientation or potential bound swapping.
Dimensional Analysis
The diagonal vector provides essential geometric measurements:
- X-component: Width along the X-axis
- Y-component: Height along the Y-axis
- Z-component: Depth along the Z-axis
Additional derived measurements include:
- Volume:
- Surface Area:
- Space Diagonal:
Applications
Diagonal calculations serve multiple computational purposes:
- Level of Detail: Distance-based quality adjustments using diagonal magnitude
- Spatial Indexing: Grid cell sizing for spatial hash tables
- Collision Detection: Broad-phase filtering using diagonal extents
- Memory Allocation: Buffer sizing based on dimensional requirements
ライブエディター
const fragment = () => Scope(() => { const t = iTime.mul(0.3) const p = uv.mul(4).sub(2) const box = AABB({ minBounds: vec3(t.sin().mul(0.8).sub(1.2), t.mul(1.4).cos().mul(0.6).sub(0.8), 0), maxBounds: vec3(t.mul(1.1).sin().mul(1.1).add(0.4), t.mul(0.8).cos().mul(0.9).add(0.6), 0) }) const diag = diagonal(box) const center = aabbCentroid(box) const relPos = p.sub(center.xy) const normPos = relPos.div(diag.xy.mul(0.5)) const intensity = length(normPos).saturate().oneMinus() const stripes = normPos.x.mul(diag.x).mul(8).sin().mul(0.5).add(0.5) const edgeX = p.x.sub(box.minBounds.x).abs() .min(p.x.sub(box.maxBounds.x).abs()) const edgeY = p.y.sub(box.minBounds.y).abs() .min(p.y.sub(box.maxBounds.y).abs()) const wireframe = smoothstep(0.02, 0.04, edgeX.min(edgeY)).oneMinus() const color = intensity.mul(vec3(diag.x.mul(0.3), diag.y.mul(0.4), 0.6)).add(stripes.mul(0.2)) return vec4(color.add(wireframe.mul(0.5)), 1) })