transformation-matrix
官网说它是经过完备的测试的库。是一个用ES6写的一个可以支持任意2D仿射变换的库。
transformation-matrix library 支持以下功能
- generate transformation matrices for the following operations: translation, rotation, scale, shear, skew
- merge multiple transformation matrices in a single matrix that is the composition of multiple matrices
- work with strings in both directions: parse, render
- apply a transformation matrix to point(s)
- decompose a matrix into translation, scaling and rotation components, with flip decomposition support
API
Operations:
- identity
- flipX 绕X轴翻转,关于X轴镜像
- flipY 绕Y轴翻转,关于Y轴镜像
- flipOrigin 绕原点翻转,关于原点镜像
- rotate(angle, [cx], [cy]) angle为弧度,绕着(cx,cy)旋转,默认是坐标原点
- rotateDEG(angle, [cx], [cy]) angle为角度,绕着(cx,cy)旋转,默认是坐标原点
- scale(sx, [sy], [cx], [cy]) sx,x轴缩放因子,sy,y轴缩放因子 如果(cx,cy)提供,则关于该点缩放
- shear(shx, shy) shx,x轴裁剪因子,shy,y轴裁剪因子
- skew(ax, ay)
- skewDEG(ax, ay)
- smoothMatrix(matrix, [precision])
- translate(tx, [ty])
- inverse(matrix)
Calculate
- fromDefinition(definitionOrArrayOfDefinition)
- fromObject(object)
- fromString(string)
- fromTransformAttribute(transformString)
- fromTriangles(t1,t2)
Apply
- applyToPoint(matrix,point)
- applyToPoints(matrix, points)
Stringify
- toCSS(matrix)
- toSVG(matrix)
- toString(matrix)
Compose
- transform(matrices)
- compose(matrices)
Decompose
- decomposeTSR(matrix,flipX,flipY)
Moving points(gestures)
- fromOneMovingPoint(startingPoint,endingPoint)
- fromTwoMovingPoints(startingPoint1,startingPoint2,endingPoint1,endingPoint2)