{"id":22530122,"url":"https://github.com/bohnacker/stretch_transform","last_synced_at":"2026-03-10T13:04:30.453Z","repository":{"id":57372243,"uuid":"109592237","full_name":"bohnacker/Stretch_Transform","owner":"bohnacker","description":"Javascript library/class for distorting a plane or 3D space.","archived":false,"fork":false,"pushed_at":"2020-02-25T07:52:55.000Z","size":973,"stargazers_count":6,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-10-16T06:33:54.094Z","etag":null,"topics":["distortion","geometry","javascript-library","transformation"],"latest_commit_sha":null,"homepage":"","language":"Processing","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/bohnacker.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-11-05T15:38:12.000Z","updated_at":"2023-04-25T03:10:29.000Z","dependencies_parsed_at":"2022-09-10T01:20:27.546Z","dependency_job_id":null,"html_url":"https://github.com/bohnacker/Stretch_Transform","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bohnacker%2FStretch_Transform","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bohnacker%2FStretch_Transform/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bohnacker%2FStretch_Transform/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bohnacker%2FStretch_Transform/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bohnacker","download_url":"https://codeload.github.com/bohnacker/Stretch_Transform/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245972672,"owners_count":20702721,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":["distortion","geometry","javascript-library","transformation"],"created_at":"2024-12-07T07:18:24.840Z","updated_at":"2026-03-10T13:04:30.375Z","avatar_url":"https://github.com/bohnacker.png","language":"Processing","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Stretch Transform\n\nStretch Transform is a geometric transformation that distorts a plane or 3D space in a rubbery way. \n\n![Cover](/images/cover.jpg)\n\nFor a more detailed explanation of this project read [this](https://hartmut-bohnacker.de/projects/stretch-transform) on my website.\n\n\n## Quick start\n\n#### 1. Install the library:\n\nVia NPM:\n```\nnpm i stretch-transform\n```\n\nOr in your html file:\n``` html\n\u003cscript src=\"StretchTransform.js\"\u003e\u003c/script\u003e\n```\n\n#### 2. Start creating a new StretchTransform:\n``` javascript\nvar myTransform = new StretchTransform();\n```\n\n#### 3. Add some anchors.\n\nUsually you'll give two points as parameters. The first point (origin) will be transformed exactly to the second point (target).\n``` javascript\nmyTransform.addAnchor([100, 200], [300, 300]);\n```\n\nIf you give only point as a parameter origin and target will be set to that position. You could change either of them later on.\n``` javascript\nmyTransform.addAnchor([100, 200]);\n```\n\nStretchTransform also works in 3D space. In fact, it always does. \n``` javascript\nmyTransform.addAnchor([100, 200, -150], [300, 300, 0]);\n```\n\n#### 4. Transform any point you want.\n``` javascript\nvar result = myTransform.transform([200, 200, 50]);\n```\n\n## Reference\n\n\u003c!-- Generated by documentation.js. Update this documentation by updating the source code. --\u003e\n\n### Table of Contents\n\n-   [StretchTransform](#stretchtransform)\n    -   [addAnchor](#addanchor)\n    -   [addAnchor](#addanchor-1)\n    -   [removeAnchor](#removeanchor)\n    -   [removeAnchor](#removeanchor-1)\n    -   [getAnchorCount](#getanchorcount)\n    -   [getAnchor](#getanchor)\n    -   [getAnchorByPos](#getanchorbypos)\n    -   [getAnchorByOriginPos](#getanchorbyoriginpos)\n    -   [getAnchorByTargetPos](#getanchorbytargetpos)\n    -   [getAnchorOrigin](#getanchororigin)\n    -   [setAnchorOrigin](#setanchororigin)\n    -   [getAnchorTarget](#getanchortarget)\n    -   [setAnchorTarget](#setanchortarget)\n    -   [getWeightingExponent1](#getweightingexponent1)\n    -   [setWeightingExponent1](#setweightingexponent1)\n    -   [getWeightingExponent2](#getweightingexponent2)\n    -   [setWeightingExponent2](#setweightingexponent2)\n    -   [transform](#transform)\n    -   [updateAnchorMatrices](#updateanchormatrices)\n-   [Anchor](#anchor)\n    -   [getOriginPosition](#getoriginposition)\n    -   [setOriginPosition](#setoriginposition)\n    -   [getTargetPosition](#gettargetposition)\n    -   [setTargetPosition](#settargetposition)\n    -   [getTransformMatrix](#gettransformmatrix)\n\n## StretchTransform\n\nnew StretchTransform() creates an empty StretchTransform.\n\n### addAnchor\n\nAdds an Anchor where origin and target is the same. You can change either of them later on.\n\n**Parameters**\n\n-   `p` **[Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)** Array [x, y, z] that will be used for origin and target position. Z coordinate is optional.\n\nReturns **[Anchor](#anchor)** The new anchor\n\n### addAnchor\n\nAdds an Anchor. pOrigin will be transformed to pTarget.\n\n**Parameters**\n\n-   `pOrigin` **[Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)** Array [x, y, z] for the origin position. Z coordinate is optional.\n-   `pTarget` **[Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)** Array [x, y, z] for the target position. Z coordinate is optional.\n\nReturns **[Anchor](#anchor)** The new anchor\n\n### removeAnchor\n\nRemoves an Anchor giving the anchor\n\n**Parameters**\n\n-   `anchor` **[Anchor](#anchor)** Anchor to remove\n\n### removeAnchor\n\nRemoves an Anchor giving the index of the anchor.\n\n**Parameters**\n\n-   `i` **[Number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** Index of the anchor\n\n### getAnchorCount\n\nReturns **[Number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** of anchors added to the MultiTransform\n\n### getAnchor\n\n**Parameters**\n\n-   `i` **[Number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** Index of the anchor to return.\n\n### getAnchorByPos\n\n**Parameters**\n\n-   `p` **[Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)** point [x, y, z] to search for an anchor (either origin or target position). Z coordinate is optional.\n-   `tolerance` **[Number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** Radius around Anchor\n\nReturns **[Number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** Index of the found anchor or -1 if nothing was found at the specified position\n\n### getAnchorByOriginPos\n\n**Parameters**\n\n-   `p` **[Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)** point [x, y, z] to search for the origin position of an anchor. Z coordinate is optional.\n-   `tolerance` **[Number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** Radius around Anchor\n\nReturns **[Number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** Index of the found anchor or -1 if nothing was found at the\n        specified position\n\n### getAnchorByTargetPos\n\n**Parameters**\n\n-   `p` **[Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)** point [x, y, z] to search for the target position of an anchor. Z coordinate is optional.\n-   `tolerance` **[Number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** Radius around Anchor\n\nReturns **[Number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** Index of the found anchor or -1 if nothing was found at the\n        specified position\n\n### getAnchorOrigin\n\n**Parameters**\n\n-   `i` **[Number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** Index of the anchor.\n\nReturns **[Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)** The origin position.\n\n### setAnchorOrigin\n\n**Parameters**\n\n-   `i` **[Number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** Index of the anchor.\n-   `p` **[Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)** New origin position [x, y, z]. Z coordinate is optional.\n\n### getAnchorTarget\n\n**Parameters**\n\n-   `i` **[Number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** Index of the anchor.\n\nReturns **[Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)** The target position.\n\n### setAnchorTarget\n\n**Parameters**\n\n-   `i` **[Number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** Index of the anchor.\n-   `p` **[Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)** New target position [x, y, z]. Z coordinate is optional.\n\n### getWeightingExponent1\n\nReturns **[Number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** \n\n### setWeightingExponent1\n\nExponent of the weighting function. Defines how the relations from one anchor to all others are cumulated. The closer the other anchor lies, the stronger it is weighted.\n\n**Parameters**\n\n-   `val` **[Number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** Usually something between 0 and 2. Default = 1.\n\n### getWeightingExponent2\n\nReturns **[Number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** \n\n### setWeightingExponent2\n\nExponent of the weighting function when applying all anchor matrices to a\npoint.\n\n**Parameters**\n\n-   `val` **[Number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** Usually 1 or higher. Default = 2.\n\n### transform\n\nMain function of the class. Transforms a point on the plane and returns\nits new position.\n\n**Parameters**\n\n-   `p` **[Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)** Point given as an Array [x, y, z] to be transformed. Z coordinate is optional.\n\nReturns **[Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)** Transformed point as an Array.\n\n### updateAnchorMatrices\n\nIt's usually not necessary to call this method. If anchors and parameters\nare always set with the given methods (setAnchorOrigin(), ...), this\nmethod will be called automatically. It calculates a transformation\nmatrix for each anchor. This matrix reflects the translation of the\nanchor and the rotation and scaling depending on the (possibly) changed\npositions of all other anchors.\n\n### Anchor\n\nAn Anchor has an origin an a target position. Usually you won't have to deal with it directly. Still, there are some functions which could come handy.\n\n**Parameters**\n\n-   `pOrigin`  \n-   `pTarget`  \n\n### getOriginPosition\n\nReturns **[Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)** The origin position.\n\n### setOriginPosition\n\n**Parameters**\n\n-   `p` **[Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)** New origin position [x, y, z]. Z coordinate is optional.\n\n### getTargetPosition\n\nReturns **[Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)** The target position.\n\n### setTargetPosition\n\n**Parameters**\n\n-   `p` **[Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)** New target position [x, y, z]. Z coordinate is optional.\n\n### getTransformMatrix\n\nReturns **[Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)** The transformation matrix of this anchor.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbohnacker%2Fstretch_transform","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbohnacker%2Fstretch_transform","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbohnacker%2Fstretch_transform/lists"}