How can I apply an SVGMatrix to an array of points?

前端 未结 1 1910
误落风尘
误落风尘 2021-01-28 14:01

Are there built-in libraries to multiply a vector of points by an SVGMatrix?

I have an SVG drawing that has been scaled, and I want to annotate that drawing in its origi

相关标签:
1条回答
  • 2021-01-28 14:30

    The svg element has methods from creating matrix objects and point objects. The matrix object has methods for matrix operations (e.g. multiply, translate, scale, etc). The point object has method to apply matrix transform.

    For example...

    var svg = document.getElementById("mySvg");
    var matrix1 = svg.createSVGMatrix();
    var matrix2 = matrix1.translate(2, 3);
    var point1 = svg.createSVGPoint();
    point1.x = 1;
    point1.y = 1;
    var point2 = point1.matrixTransform(matrix2);
    

    Documentation for the matrix and point objects can be found at...

    http://www.w3.org/TR/SVG/single-page.html#coords-InterfaceSVGPoint http://www.w3.org/TR/SVG/single-page.html#coords-InterfaceSVGMatrix

    0 讨论(0)
提交回复
热议问题