skills/tabular/convex-hull-bbox-rotation/SKILL.md
Minimize axis-aligned bounding box side length by finding the optimal rotation angle over convex hull vertices using bounded scalar optimization
npx skillsauth add wenmin-wu/ds-skills tabular-convex-hull-bbox-rotationInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
An axis-aligned bounding box is rarely the tightest enclosure. Rotating the point cloud before computing the AABB can significantly reduce its area or max side length. Only the convex hull vertices matter, so reduce to hull first. Then use scipy.optimize.minimize_scalar to find the rotation angle that minimizes the bounding box metric — much faster than brute-force angle sweeps.
import numpy as np
from scipy.optimize import minimize_scalar
from scipy.spatial import ConvexHull
def bbox_side_at_angle(angle_deg, points):
rad = np.radians(angle_deg)
c, s = np.cos(rad), np.sin(rad)
rot = np.array([[c, s], [-s, c]])
rotated = points @ rot
span = rotated.max(axis=0) - rotated.min(axis=0)
return max(span[0], span[1])
def optimal_bbox_rotation(all_points):
pts = np.array(all_points)
hull_pts = pts[ConvexHull(pts).vertices]
initial = bbox_side_at_angle(0, hull_pts)
res = minimize_scalar(
lambda a: bbox_side_at_angle(a, hull_pts),
bounds=(0.001, 89.999), method='bounded')
if initial - res.fun > 1e-10:
return res.fun, res.x
return initial, 0.0
best_side, best_angle = optimal_bbox_rotation(points)
points @ rot.T is vectorized and fast for large point setsdata-ai
Scaled Pinball Loss (SPL) metric for evaluating quantile forecasts, normalized by mean absolute successive differences of training data
data-ai
Walk backward through a time series and multiplicatively rescale segments when jumps exceed a fraction of the running mean to correct data collection anomalies
testing
Transform forecasting target to next/current ratio minus one so that optimizing MAE or squared error implicitly minimizes SMAPE
tools
Convert point forecasts to prediction intervals by scaling with logit-transformed quantile ratios passed through a Normal CDF