Skip to content

Commit 45eda9a

Browse files
committed
p5.Matrix cleanup documentaiton rotate and others
1 parent 72955e4 commit 45eda9a

File tree

2 files changed

+31
-14
lines changed

2 files changed

+31
-14
lines changed

src/math/Matrices/Matrix.js

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -812,22 +812,20 @@ export class Matrix extends MatrixInterface {
812812
* @returns {Matrix} The current matrix after applying the transformation.
813813
*
814814
* @example
815+
* <div class="norender"><code>
816+
* function setup() {
817+
*
815818
* // Assuming `matrix` is an instance of Matrix
816819
* const anotherMatrix = new p5.Matrix();
817820
* matrix.apply(anotherMatrix);
818821
*
819-
* @example
820822
* // Applying a transformation using an array
821823
* const matrixArray = [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1];
822824
* matrix.apply(matrixArray);
823825
*
824-
* @example
825826
* // Applying a transformation using individual arguments
826827
* matrix.apply(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1);
827828
*
828-
* // p5.js script example
829-
* <div class="norender"><code>
830-
* function setup() {
831829
*
832830
* // Create a 4x4 identity matrix
833831
* const matrix = new p5.Matrix(4);
@@ -988,9 +986,29 @@ export class Matrix extends MatrixInterface {
988986
}
989987

990988
/**
989+
* Rotate the Matrix around a specified axis by a given angle.
990+
*
991+
* This method applies a rotation transformation to the matrix, modifying its orientation
992+
* in 3D space. The rotation is performed around the provided axis, which can be defined
993+
* as a `p5.Vector` or an array of numbers representing the x, y, and z components of the axis.
991994
* Rotate our Matrix around an axis by the given angle.
992-
* @param {Number} a The angle of rotation in radians
993-
* @param {p5.Vector|Number[]} axis the axis(es) to rotate around
995+
* @param {Number} a The angle of rotation in radians.
996+
* Angles in radians are a measure of rotation, where 2π radians
997+
* represent a full circle (360 degrees). For example:
998+
* - π/2 radians = 90 degrees (quarter turn)
999+
* - π radians = 180 degrees (half turn)
1000+
* - 2π radians = 360 degrees (full turn)
1001+
* Use `Math.PI` for π or `p5`'s `PI` constant if using p5.js.
1002+
* @param {p5.Vector|Number[]} axis The axis or axes to rotate around.
1003+
* This defines the direction of the rotation.
1004+
* - If using a `p5.Vector`, it should represent
1005+
* the x, y, and z components of the axis.
1006+
* - If using an array, it should be in the form
1007+
* [x, y, z], where x, y, and z are numbers.
1008+
* For example:
1009+
* - [1, 0, 0] rotates around the x-axis.
1010+
* - [0, 1, 0] rotates around the y-axis.
1011+
* - [0, 0, 1] rotates around the z-axis. *
9941012
* @chainable
9951013
* inspired by Toji's gl-matrix lib, mat4 rotation
9961014
*/

src/math/math.js

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* @requires core
55
*/
66

7-
function math(p5, fn){
7+
function math(p5, fn) {
88
/**
99
* Creates a new <a href="#/p5.Vector">p5.Vector</a> object.
1010
*
@@ -90,7 +90,7 @@ function math(p5, fn){
9090
*
9191
* // Draw the dot.
9292
* strokeWeight(5);
93-
* point(pos);
93+
* point(pos);
9494
* }
9595
* </code>
9696
* </div>
@@ -113,18 +113,17 @@ function math(p5, fn){
113113
* A matrix is a mathematical concept that is useful in many fields, including
114114
* computer graphics. In p5.js, matrices are used to perform transformations
115115
* on shapes and images. The `createMatrix` method can take a column-major
116-
* array representation of a square matrix as an argument.
116+
* array representation of a square matrix as an argument. In the current implementation we only use squared matrices.
117117
*
118118
* @method createMatrix
119-
* @param {Array<Number>} components Column-major array representation of the matrix.
119+
* @param {Array<Number>} components Column-major array representation of the square matrix.
120120
*
121121
* @return {p5.Matrix} new <a href="#/p5.Matrix">p5.Matrix</a> object.
122122
*
123123
* @example
124-
* <div>
124+
* <div class="norender">
125125
* <code>
126126
* function setup() {
127-
* createCanvas(100, 100);
128127
* let matrix = createMatrix([1, 2, 3, 4, 5, 6, 7, 8, 9]);
129128
* }
130129
* </code>
@@ -137,6 +136,6 @@ function math(p5, fn){
137136

138137
export default math;
139138

140-
if(typeof p5 !== 'undefined'){
139+
if (typeof p5 !== "undefined") {
141140
math(p5, p5.prototype);
142141
}

0 commit comments

Comments
 (0)