{"id":26973957,"url":"https://github.com/herrstrietzel/mtrxyz","last_synced_at":"2026-02-18T13:01:55.710Z","repository":{"id":280567561,"uuid":"941582436","full_name":"herrstrietzel/mtrXYZ","owner":"herrstrietzel","description":"A helper for 3D and 2D matrix transformations ","archived":false,"fork":false,"pushed_at":"2025-03-12T02:26:32.000Z","size":644,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-10-23T05:56:58.518Z","etag":null,"topics":["2d-matrix","3d-matrix","perspective","point-projection","svg"],"latest_commit_sha":null,"homepage":"https://herrstrietzel.github.io/mtrXYZ/","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/herrstrietzel.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-03-02T16:26:45.000Z","updated_at":"2025-03-12T02:26:38.000Z","dependencies_parsed_at":"2025-06-17T14:50:13.814Z","dependency_job_id":null,"html_url":"https://github.com/herrstrietzel/mtrXYZ","commit_stats":null,"previous_names":["herrstrietzel/matrixyz","herrstrietzel/mtrxyz"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/herrstrietzel/mtrXYZ","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/herrstrietzel%2FmtrXYZ","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/herrstrietzel%2FmtrXYZ/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/herrstrietzel%2FmtrXYZ/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/herrstrietzel%2FmtrXYZ/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/herrstrietzel","download_url":"https://codeload.github.com/herrstrietzel/mtrXYZ/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/herrstrietzel%2FmtrXYZ/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29580638,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-18T08:38:15.585Z","status":"ssl_error","status_checked_at":"2026-02-18T08:38:14.917Z","response_time":162,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["2d-matrix","3d-matrix","perspective","point-projection","svg"],"created_at":"2025-04-03T10:19:49.397Z","updated_at":"2026-02-18T13:01:55.688Z","avatar_url":"https://github.com/herrstrietzel.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![npm version](https://img.shields.io/npm/v/mtrxyz)](https://www.npmjs.com/package/mtrxyz)\n[![gzipped size](https://img.shields.io/bundlephobia/minzip/mtrxyz)](https://bundlephobia.com/result?p=mtrxyz)\n[![minified size](https://img.shields.io/bundlephobia/min/mtrxyz)](https://bundlephobia.com/result?p=mtrxyz)\n[![license](https://img.shields.io/npm/l/mtrxyz)](https://www.npmjs.com/package/mtrxyz)\n[![CDN](https://img.shields.io/badge/CDN-jsDelivr-E84D3D?style=flat)](https://cdn.jsdelivr.net/npm/mtrxyz@latest/MtrXYZ.min.js)\n[![CDN](https://img.shields.io/badge/CDN-unpkg-blue?style=flat)](https://www.unpkg.com/mtrxyz@latest/dist/MtrXYZ.min.js)\n\n# mtrXYZ\nA helper for 3D and 2D matrix transformations \n\n## Usage\n\n### Install\n```\n\u003cscript src=\"https://cdn.jsdelivr.net/npm/mtrxyz@latest/dist/MtrXYZ.min.js\" defer\u003e\u003c/script\u003e\n```\n\nIf you need to transform SVG path data please also load the pathdata addon\n\n```\n\u003cscript src=\"https://cdn.jsdelivr.net/npm/mtrxyz@latest/dist/MtrXYZ_pathdata.min.js\" defer\u003e\u003c/script\u003e\n```\n\n\n\n### Create Matrix\n\nMatriXYZ replicates CSS transformation properties allowing multiple chained tranformations. \nBasically, you use the typical main transformation properties:  \n\n* translate\n* scale\n* skew\n* rotate \n\nBesides, you can specify a `transform-origin` as well as a `perspective-origin` and `perspective` value fo a full 3D transformation projection.\n\n\n\n```\n// create 3D transformation object\nlet transformOptions = {\n    // add chainable option analogous to CSS\n    transforms: [\n        { translate: [translateX, translateY, translateZ] },\n        { scale: [scaleX, scaleY, scaleZ] },\n        { skew: [skewX, skewY] },\n        { rotate: [rotateX, rotateY, rotateZ] },\n    ],\n    transFormOrigin: { x: transformOriginX, y: transformOriginY },\n    perspectiveOrigin: { x: perspectiveOriginX, y: perspectiveOriginY },\n    perspective: perspective,\n    force3D: force3D\n}\n\n/**\n* create matrix\n*/\nlet matrix = new MatriXYZ.Mtx(transformOptions);\n\n```\n\nThe above example creates a 3D matrix based on the specified parameters.  \n`new MatriXYZ.Mtx(transformOptions)` creates a custom matrix object we can reuse for point projections.\n\n### Point transformation/projection\n\nOnce we got a matrix, we can apply it to multiple point arrays like:  \n* point object arrays `[{x:10, y:10, z:10}]` – yeah 3D points are supported\n* nested point  arrays `[[10, 10]]`\n* SVG pathData like  `M20.1 120.8 L20.1 120.8 Q11.2 120.8 5.6 117.4 Q0 114 0 107.7` – requires the pathdata addon\n\n\n#### Get tranformed/projected points\n```\n\nlet points = [[50,85.2],[83.4,57.4],[95.4,43],[100,25],[92.7,7.4],[75,0.1],[57.3,7.4],[50,25],[42.7,7.4],[25,0.1],[7.3,7.4],[0,25],[4.5,43.1],[16.6,57.4],[50,85.2]];\n\nlet ptsTransformed = matrix.transformPoints(points, decimals)\n```\n\n#### Get tranformed/projected SVG pathData\n```\nlet pathdata = 'M50 85.2 83.4 57.4 95.4 43 100 25 92.7 7.4 75 0.1 57.3 7.4 50 25 42.7 7.4 25 0.1 7.3 7.4 0 25 4.5 43.1 16.6 57.4 50 85.2'\nlet pathDataTransformed = matrix.transformPathData(pathdata, decimals)\n\n// optimize output\nlet options = {\n    // round to decimals\n    decimals:3, \n\n    // convert to relative commands\n    toRelative:true, \n\n    // try to apply shorthand commands\n    toShorthands:true, \n\n    // convert arcs to cubic beziers (automatically applied for 3D transforms)\n    arcToCubic:false\n}\nlet pathDataOpt = MatriXYZ.pathDataToD(pathDataTransformed, options)\n\n\n// stringify to d attribute\nlet d = MatriXYZ.pathDataToD(pathDataOpt)\n\n```\n\n\n\n\n#### Order of tranformations matters!\nWe use the same logic as CSS – so transformations are applied from right(last) to left(first). \nThis also allows you to chain transforms the same way as in CSS.  \n\n```\n// 2D transformation\nlet transformOptions = {\n    transforms: [\n        { translate: [10, 30] },\n        { scale: [1.5, 1.75] },\n        { skew: [10, 15] },\n        { rotate: [45] },\n        // 2nd translate\n        { translate: [5, 8] },\n    ],\n}\n```\ntranslates to CSS:\n\n```\ntransform: translateX(10px) translateY(30px) scaleX(1.5) scaleY(1.75) rotate(45deg) translateX(5px) translateY(8px);\n```\n\nAll properties support 2D and 3D structures – so 1 to 3 values.  \nCSS only supports `skewX` and `skewY` – so there is no `skewZ`.\nA single value for rotate is automatically interpreted as `rotateZ` – resulting in a 2D rotation.  \n\n\n## Credits\n\n* Jarek Foksa for his [great polyfill](https://github.com/jarek-foksa/path-data-polyfill) heavily inspring to adopt the new pathData interface methodology and for contributing to the specification\n* Dmitry Baranovskiy for (raphael.j/snap.svg) [pathToAbsolute/Relative functions](https://github.com/DmitryBaranovskiy/raphael/blob/master/raphael.js#L1848) \n* Vitaly Puzrin (fontello) for the arc to cubic conversion method  [a2c.js](https://github.com/fontello/svgpath/blob/master/lib/a2c.js) and [cubic to quadratic approximation](https://github.com/fontello/cubic2quad/blob/master/test/cubic2quad.js) as well as the [2D transformation of elliptic arcs](https://github.com/fontello/svgpath/blob/master/lib/ellipse.js)\n* Mike \"POMAX\" Kammermans for his great [A Primer on Bézier Curves](https://pomax.github.io/bezierinfo)\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fherrstrietzel%2Fmtrxyz","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fherrstrietzel%2Fmtrxyz","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fherrstrietzel%2Fmtrxyz/lists"}