Geometry algorithms for dance choreography - centroid, spreader, arrangement, collision
npm install danceflow-geometryGeometry algorithms for dance choreography formations.
``bash`
npm install danceflow-geometry
`javascript
import {
calculateCentroid,
spreadFromCentroid,
arrangeInLine,
arrangeInCircle,
isPointInPolygon
} from 'danceflow-geometry';
// Calculate center of dancers
const positions = [{ x: 100, y: 100 }, { x: 200, y: 150 }];
const center = calculateCentroid(positions);
// Spread dancers from center
const spread = spreadFromCentroid(positions, 1.5);
`
- Find center point of a group of positions
- scaleAroundCenter(positions, scale) - Scale positions around their centroid$3
- spreadFromCentroid(positions, factor) - Expand/contract from center point
- spreadHorizontal(positions, factor) - Spread horizontally only
- spreadVertical(positions, factor) - Spread vertically only$3
- arrangeInLine(positions, start, end) - Arrange in a straight line
- arrangeInColumn(positions, start, spacing) - Arrange in a vertical column
- arrangeInDiagonal(positions, start, angle, spacing) - Arrange diagonally$3
- arrangeInCircle(positions, center, radius) - Arrange in a circle
- arrangeInArc(positions, center, radius, startAngle, endAngle) - Arrange in an arc
- arrangeInSpiral(positions, center, startRadius, endRadius) - Arrange in a spiral$3
- mirrorHorizontal(positions, axisX) - Mirror across vertical axis
- mirrorVertical(positions, axisY) - Mirror across horizontal axis
- flipFormation(positions) - Flip entire formation$3
- rotateFormation(positions, angle) - Rotate around centroid
- rotateAroundPoint(positions, point, angle) - Rotate around specific point$3
- isPointInPolygon(point, polygon) - Point-in-polygon test (ray casting)
- createPolygonPath(points) - Create closed polygon path$3
- cubicBezier(t, p0, p1, p2, p3) - Cubic bezier interpolation
- quadraticBezier(t, p0, p1, p2) - Quadratic bezier interpolation
- calculateOptimalArcHeight(start, end) - Calculate optimal arc control point$3
- catmullRomSpline(points, t) - Catmull-Rom spline interpolation
- createSmoothPath(points, segments) - Create smooth path through points$3
- detectCollisions(positions, radius) - Find overlapping positions
- resolveOverlaps(positions, minDistance) - Push apart overlapping positionsTypes
`typescript
interface Point {
x: number;
y: number;
}interface DancerPosition {
x: number;
y: number;
facing: number;
}
``MIT