Skip to content

Commit dc881ec

Browse files
committed
p5.Matrix example for rotatate4x4 remove comments p5
1 parent 45eda9a commit dc881ec

File tree

2 files changed

+46
-28
lines changed

2 files changed

+46
-28
lines changed

src/math/Matrices/Matrix.js

Lines changed: 45 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ export class Matrix extends MatrixInterface {
8383
* const matrix2 = new p5.Matrix([4, 5, 6]);
8484
* matrix1.add(matrix2); // matrix1 is now [5, 7, 9]
8585
*
86-
* // p5.js script example
86+
*
8787
* <div class="norender"><code>
8888
* function setup() {
8989
*
@@ -148,7 +148,7 @@ export class Matrix extends MatrixInterface {
148148
* // Assuming matrix is an instance of Matrix with initial values [1, 2, 3, 4] matrix.setElement(2, 99);
149149
* // Now the matrix values are [1, 2, 99, 4]
150150
*
151-
* // p5.js script example
151+
*
152152
* <div class="norender"><code>
153153
* function setup() {
154154
*
@@ -182,7 +182,7 @@ export class Matrix extends MatrixInterface {
182182
* matrix.reset(); // Reset to identity matrix
183183
* console.log(matrix.matrix); // Output: Identity matrix
184184
*
185-
* // p5.js script example
185+
*
186186
* <div class="norender"><code>
187187
* function setup() {
188188
*
@@ -234,7 +234,7 @@ export class Matrix extends MatrixInterface {
234234
* matrix.set(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16);
235235
* console.log(matrix.matrix); // Output: [1, 2, 3, ..., 16]
236236
*
237-
* // p5.js script example
237+
*
238238
* <div class="norender"><code>
239239
* function setup() {
240240
*
@@ -277,7 +277,7 @@ export class Matrix extends MatrixInterface {
277277
* same values as the original matrix.
278278
*
279279
* @example
280-
* // p5.js script example
280+
*
281281
* <div class="norender"><code>
282282
* function setup() {
283283
*
@@ -309,7 +309,7 @@ export class Matrix extends MatrixInterface {
309309
* @return {p5.Matrix} The result matrix.
310310
*
311311
* @example
312-
* // p5.js script example
312+
*
313313
* <div class="norender"><code>
314314
* function setup() {
315315
*
@@ -337,7 +337,7 @@ export class Matrix extends MatrixInterface {
337337
* @returns {Matrix} A new matrix instance that is a copy of the current matrix.
338338
*
339339
* @example
340-
* // p5.js script example
340+
*
341341
* <div class="norender"><code>
342342
* function setup() {
343343
*
@@ -384,7 +384,7 @@ export class Matrix extends MatrixInterface {
384384
* const matrix = new p5.Matrix([1, 2, 3, 4, 5, 6, 7, 8, 9]);
385385
* const diagonal = matrix.diagonal(); // [1, 5, 9]
386386
*
387-
* // p5.js script example
387+
*
388388
* <div class="norender"><code>
389389
* function setup() {
390390
*
@@ -419,7 +419,7 @@ export class Matrix extends MatrixInterface {
419419
* const matrix = new p5.Matrix([1, 2, 3, 4, 5, 6, 7, 8, 9]);
420420
* const rowVector = matrix.row(1); // Returns a vector [2, 5, 8]
421421
*
422-
* // p5.js script example
422+
*
423423
* <div class="norender"><code>
424424
* function setup() {
425425
*
@@ -454,7 +454,7 @@ export class Matrix extends MatrixInterface {
454454
* const matrix = new p5.Matrix([1, 2, 3, 4, 5, 6, 7, 8, 9]);
455455
* const columnVector = matrix.column(1); // Returns a vector [4, 5, 6]
456456
*
457-
* // p5.js script example
457+
*
458458
* <div class="norender"><code>
459459
* function setup() {
460460
*
@@ -497,7 +497,7 @@ export class Matrix extends MatrixInterface {
497497
* matrix4x4.transpose();
498498
* console.log(matrix4x4.matrix); // Output: Transposed 4x4 identity matrix
499499
*
500-
* // p5.js script example
500+
*
501501
* <div class="norender"><code>
502502
* function setup() {
503503
*
@@ -548,7 +548,7 @@ export class Matrix extends MatrixInterface {
548548
* matrix4x4_1.mult(matrix4x4_2);
549549
* console.log(matrix4x4_1.matrix); // Output: [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 1, 2, 3, 1]
550550
*
551-
* // p5.js script example
551+
*
552552
* <div class="norender"><code>
553553
* function setup() {
554554
*
@@ -601,7 +601,7 @@ export class Matrix extends MatrixInterface {
601601
* const result = matrix.multiplyVec(vector);
602602
* console.log(result.toString()); // Output: Transformed vector
603603
*
604-
* // p5.js script example
604+
*
605605
* <div class="norender"><code>
606606
* function setup() {
607607
*
@@ -650,7 +650,7 @@ export class Matrix extends MatrixInterface {
650650
* const invertedMatrix4x4 = matrix4x4.invert();
651651
* console.log(invertedMatrix4x4.matrix); // Output: Inverted 4x4 matrix
652652
*
653-
* // p5.js script example
653+
*
654654
* <div class="norender"><code>
655655
* function setup() {
656656
*
@@ -699,7 +699,7 @@ export class Matrix extends MatrixInterface {
699699
* console.log("Original 4x4 Matrix:", matrix4x4.matrix);
700700
* console.log("Extracted 3x3 Submatrix:", subMatrix3x3.matrix);
701701
*
702-
* // p5.js script example
702+
*
703703
* <div class="norender"><code>
704704
* function setup() {
705705
*
@@ -751,7 +751,7 @@ export class Matrix extends MatrixInterface {
751751
* mat3.inverseTranspose4x4(mat4);
752752
* console.log("Converted 3×3 Matrix:", mat3.matrix);
753753
*
754-
* // p5.js script example
754+
*
755755
* <div class="norender"><code>
756756
* function setup() {
757757
*
@@ -933,7 +933,7 @@ export class Matrix extends MatrixInterface {
933933
* matrix.scale(scaleArray);
934934
* console.log(matrix.matrix);
935935
*
936-
* // p5.js script example
936+
*
937937
* <div class="norender"><code>
938938
* function setup() {
939939
*
@@ -1011,6 +1011,24 @@ export class Matrix extends MatrixInterface {
10111011
* - [0, 0, 1] rotates around the z-axis. *
10121012
* @chainable
10131013
* inspired by Toji's gl-matrix lib, mat4 rotation
1014+
*
1015+
* @example
1016+
*
1017+
* <div class="norender"><code>
1018+
* function setup() {
1019+
* const matrix = new p5.Matrix(4); // Create a 4x4 identity matrix
1020+
* console.log("Original Matrix:", matrix.matrix);
1021+
*
1022+
* // Rotate the matrix 90 degrees (PI/2 radians) around the Y-axis
1023+
* matrix.rotate4x4(Math.PI / 2, [0, 1, 0]);
1024+
* console.log("After Rotation (Y-axis, 90 degrees):", matrix.matrix);
1025+
*
1026+
* // Rotate the matrix 45 degrees (PI/4 radians) around a custom axis
1027+
* const axis = new p5.Vector(1, 1, 0); // Custom axis
1028+
* matrix.rotate4x4(Math.PI / 4, axis);
1029+
* console.log("After Rotation (Custom Axis, 45 degrees):", matrix.matrix);
1030+
* }
1031+
* </code></div>
10141032
*/
10151033
rotate4x4(a, x, y, z) {
10161034
if (x instanceof Vector) {
@@ -1097,7 +1115,7 @@ export class Matrix extends MatrixInterface {
10971115
* matrix.translate([5, 15]); // Translate by 5 units along x and 15 along y
10981116
* console.log(matrix.matrix);
10991117
*
1100-
* // p5.js script example
1118+
*
11011119
* <div class="norender"><code>
11021120
* function setup() {
11031121
*
@@ -1147,7 +1165,7 @@ export class Matrix extends MatrixInterface {
11471165
* matrix.rotateX(Math.PI / 4); // Rotate 45 degrees around the X-axis
11481166
* console.log(matrix.matrix);
11491167
*
1150-
* // p5.js script example
1168+
*
11511169
* <div class="norender"><code>
11521170
* function setup() {
11531171
*
@@ -1184,7 +1202,7 @@ export class Matrix extends MatrixInterface {
11841202
* matrix.rotateY(Math.PI / 4); // Rotate 45 degrees around the Y-axis
11851203
* console.log(matrix.matrix);
11861204
*
1187-
* // p5.js script example
1205+
*
11881206
* <div class="norender"><code>
11891207
* function setup() {
11901208
*
@@ -1223,7 +1241,7 @@ export class Matrix extends MatrixInterface {
12231241
* matrix.rotateZ(Math.PI / 4); // Rotate 45 degrees around the Z-axis
12241242
* console.log(matrix.matrix);
12251243
*
1226-
* // p5.js script example
1244+
*
12271245
* <div class="norender"><code>
12281246
* function setup() {
12291247
*
@@ -1264,7 +1282,7 @@ export class Matrix extends MatrixInterface {
12641282
* matrix.perspective(Math.PI / 4, 1.5, 0.1, 100); // Set perspective projection
12651283
* console.log(matrix.matrix);
12661284
*
1267-
* // p5.js script example
1285+
*
12681286
* <div class="norender"><code>
12691287
* function setup() {
12701288
*
@@ -1380,7 +1398,7 @@ export class Matrix extends MatrixInterface {
13801398
* const result = matrix.multiplyVec4(1, 2, 3, 1); // Transform the vector [1, 2, 3, 1]
13811399
* console.log(result); // Output: [1, 2, 3, 1] (unchanged for identity matrix)
13821400
*
1383-
* // p5.js script example
1401+
*
13841402
* <div class="norender"><code>
13851403
* function setup() {
13861404
*
@@ -1436,7 +1454,7 @@ export class Matrix extends MatrixInterface {
14361454
* const transformedPoint = matrix.multiplyPoint(point);
14371455
* console.log(transformedPoint.toString()); // Output: [1, 2, 3] (unchanged for identity matrix)
14381456
*
1439-
* // p5.js script example
1457+
*
14401458
* <div class="norender"><code>
14411459
* function setup() {
14421460
*
@@ -1489,7 +1507,7 @@ export class Matrix extends MatrixInterface {
14891507
* const transformedPoint = matrix.multiplyAndNormalizePoint(point);
14901508
* console.log(transformedPoint.toString()); // Output: [1, 2, 3] (unchanged for identity matrix)
14911509
*
1492-
* // p5.js script example
1510+
*
14931511
* <div class="norender"><code>
14941512
* function setup() {
14951513
*
@@ -1544,7 +1562,7 @@ export class Matrix extends MatrixInterface {
15441562
* const transformedDirection = matrix.multiplyDirection(direction);
15451563
* console.log(transformedDirection.toString()); // Output: [1, 0, 0] (unchanged for identity matrix)
15461564
*
1547-
* // p5.js script example
1565+
*
15481566
* <div class="norender"><code>
15491567
* function setup() {
15501568
*
@@ -1597,7 +1615,7 @@ export class Matrix extends MatrixInterface {
15971615
* const result = matrix.multiplyVec3(vector);
15981616
* console.log(result.toString()); // Output: Transformed vector
15991617
*
1600-
* // p5.js script example
1618+
*
16011619
* <div class="norender"><code>
16021620
* function setup() {
16031621
*

src/math/p5.Matrix.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ function matrix(p5, fn) {
6767
* const vector = new Vector(1, 2, 3);
6868
* const result = matrix.multiplyPoint(vector);
6969
*
70-
* // p5.js script example
70+
*
7171
* <div><code>
7272
* function setup() {
7373
*

0 commit comments

Comments
 (0)