MCPcopy Index your code
hub / github.com/processing/p5.js / normalize

Method normalize

src/webgl/p5.Geometry.js:1665–1691  ·  view source on GitHub ↗

* Transforms the geometry's vertices to fit snugly within a 100×100×100 box * centered at the origin. * * Calling `myGeometry.normalize()` translates the geometry's vertices so that * they're centered at the origin `(0, 0, 0)`. Then it scales the vertices so * that they fill a 100×100

()

Source from the content-addressed store, hash-verified

1663 * }
1664 */
1665 normalize() {
1666 if (this.vertices.length > 0) {
1667 // Find the corners of our bounding box
1668 const maxPosition = this.vertices[0].copy();
1669 const minPosition = this.vertices[0].copy();
1670
1671 for (let i = 0; i < this.vertices.length; i++) {
1672 maxPosition.x = Math.max(maxPosition.x, this.vertices[i].x);
1673 minPosition.x = Math.min(minPosition.x, this.vertices[i].x);
1674 maxPosition.y = Math.max(maxPosition.y, this.vertices[i].y);
1675 minPosition.y = Math.min(minPosition.y, this.vertices[i].y);
1676 maxPosition.z = Math.max(maxPosition.z, this.vertices[i].z);
1677 minPosition.z = Math.min(minPosition.z, this.vertices[i].z);
1678 }
1679
1680 const center = Vector.lerp(maxPosition, minPosition, 0.5);
1681 const dist = Vector.sub(maxPosition, minPosition);
1682 const longestDist = Math.max(Math.max(dist.x, dist.y), dist.z);
1683 const scale = 200 / longestDist;
1684
1685 for (let i = 0; i < this.vertices.length; i++) {
1686 this.vertices[i].sub(center);
1687 this.vertices[i].mult(scale);
1688 }
1689 }
1690 return this;
1691 }
1692
1693 /** Sets the shader's vertex property or attribute variables.
1694 *

Callers 10

loadingFunction · 0.95
saveStlMethod · 0.45
computeNormalsMethod · 0.45
_edgesToVerticesMethod · 0.45
cbFunction · 0.45
slerpMethod · 0.45
_orbitMethod · 0.45
_orbitFreeMethod · 0.45
fromAxisAngleMethod · 0.45
lightFunction · 0.45

Calls 4

subMethod · 0.80
copyMethod · 0.45
lerpMethod · 0.45
multMethod · 0.45

Tested by

no test coverage detected