danceflow-geometry
v1.0.0
Published
Geometry algorithms for dance choreography - centroid, spreader, arrangement, collision
Maintainers
Readme
danceflow-geometry
Geometry algorithms for dance choreography formations.
Installation
npm install danceflow-geometryUsage
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);Functions
Centroid
calculateCentroid(positions)- Find center point of a group of positionsscaleAroundCenter(positions, scale)- Scale positions around their centroid
Spreader
spreadFromCentroid(positions, factor)- Expand/contract from center pointspreadHorizontal(positions, factor)- Spread horizontally onlyspreadVertical(positions, factor)- Spread vertically only
Line Arrangement
arrangeInLine(positions, start, end)- Arrange in a straight linearrangeInColumn(positions, start, spacing)- Arrange in a vertical columnarrangeInDiagonal(positions, start, angle, spacing)- Arrange diagonally
Circle Arrangement
arrangeInCircle(positions, center, radius)- Arrange in a circlearrangeInArc(positions, center, radius, startAngle, endAngle)- Arrange in an arcarrangeInSpiral(positions, center, startRadius, endRadius)- Arrange in a spiral
Mirror & Flip
mirrorHorizontal(positions, axisX)- Mirror across vertical axismirrorVertical(positions, axisY)- Mirror across horizontal axisflipFormation(positions)- Flip entire formation
Rotation
rotateFormation(positions, angle)- Rotate around centroidrotateAroundPoint(positions, point, angle)- Rotate around specific point
Polygon
isPointInPolygon(point, polygon)- Point-in-polygon test (ray casting)createPolygonPath(points)- Create closed polygon path
Bezier Curves
cubicBezier(t, p0, p1, p2, p3)- Cubic bezier interpolationquadraticBezier(t, p0, p1, p2)- Quadratic bezier interpolationcalculateOptimalArcHeight(start, end)- Calculate optimal arc control point
Spline
catmullRomSpline(points, t)- Catmull-Rom spline interpolationcreateSmoothPath(points, segments)- Create smooth path through points
Collision Detection
detectCollisions(positions, radius)- Find overlapping positionsresolveOverlaps(positions, minDistance)- Push apart overlapping positions
Types
interface Point {
x: number;
y: number;
}
interface DancerPosition {
x: number;
y: number;
facing: number;
}License
MIT
