一个2D变换库学习的记录

97 阅读1分钟
transformation-matrix

本内容来自transformation-matrix

官网说它是经过完备的测试的库。是一个用ES6写的一个可以支持任意2D仿射变换的库。

transformation-matrix library 支持以下功能

  • generate transformation matrices for the following operations: translationrotationscaleshearskew
  • merge multiple transformation matrices in a single matrix that is the composition of multiple matrices
  • work with strings in both directions: parserender
  • apply a transformation matrix to point(s)
  • decompose a matrix into translation, scaling and rotation components, with flip decomposition support
API
Operations:
  1. identity
  2. flipX 绕X轴翻转,关于X轴镜像
  3. flipY 绕Y轴翻转,关于Y轴镜像
  4. flipOrigin 绕原点翻转,关于原点镜像
  5. rotate(angle, [cx], [cy]) angle为弧度,绕着(cx,cy)旋转,默认是坐标原点
  6. rotateDEG(angle, [cx], [cy]) angle为角度,绕着(cx,cy)旋转,默认是坐标原点
  7. scale(sx, [sy], [cx], [cy]) sx,x轴缩放因子,sy,y轴缩放因子 如果(cx,cy)提供,则关于该点缩放
  8. shear(shx, shy) shx,x轴裁剪因子,shy,y轴裁剪因子
  9. skew(ax, ay)
  10. skewDEG(ax, ay)
  11. smoothMatrix(matrix, [precision])
  12. translate(tx, [ty])
  13. inverse(matrix)
Calculate
  1. fromDefinition(definitionOrArrayOfDefinition)
  2. fromObject(object)
  3. fromString(string)
  4. fromTransformAttribute(transformString)
  5. fromTriangles(t1,t2)
Apply
  1. applyToPoint(matrix,point)
  2. applyToPoints(matrix, points)
Stringify
  1. toCSS(matrix)
  2. toSVG(matrix)
  3. toString(matrix)
Compose
  1. transform(matrices)
  2. compose(matrices)
Decompose
  1. decomposeTSR(matrix,flipX,flipY)
Moving points(gestures)
  1. fromOneMovingPoint(startingPoint,endingPoint)
  2. fromTwoMovingPoints(startingPoint1,startingPoint2,endingPoint1,endingPoint2)