vector_matrix_math.scad 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. matrix_3x3 = [[10,20,30],[10,20,30],[10,20,30]];
  2. vector = [2,0,0];
  3. matrix_3x2 = [[1,0,0],[1,0,0]];
  4. group0 = ["3x3matrix","vector","number","3x2matrix"];
  5. group1 = [ matrix_3x3, vector, 2, matrix_3x2];
  6. function multiply(a,b) = a * b;
  7. function divide(a,b) = a / b;
  8. function add(a,b) = a + b;
  9. function minus(a,b) = a - b;
  10. function modulus(a,b) = a % b;
  11. function lt(a,b) = a < b;
  12. function lte(a,b) = a <= b;
  13. function eq(a,b) = a == b;
  14. function neq(a,b) = a != b;
  15. function gt(a,b) = a > b;
  16. function gte(a,b) = a >= b;
  17. group1_len = len(group1);
  18. for (i = [0:group1_len-1]){
  19. for (j = [0:group1_len-1]){
  20. echo(str(group0[i]," * ",group0[j], " = "),multiply(group1[i],group1[j]));
  21. echo(str(group0[i]," / ",group0[j], " = "),divide(group1[i],group1[j]));
  22. echo(str(group0[i]," + ",group0[j], " = "),add(group1[i],group1[j]));
  23. echo(str(group0[i]," - ",group0[j], " = "),minus(group1[i],group1[j]));
  24. echo(str(group0[i]," % ",group0[j], " = "),modulus(group1[i],group1[j]));
  25. echo(str(group0[i]," < ",group0[j], " = "),lt(group1[i],group1[j]));
  26. echo(str(group0[i]," <= ",group0[j], " = "),lte(group1[i],group1[j]));
  27. echo(str(group0[i]," == ",group0[j], " = "),eq(group1[i],group1[j]));
  28. echo(str(group0[i]," != ",group0[j], " = "),neq(group1[i],group1[j]));
  29. echo(str(group0[i]," > ",group0[j], " = "),gt(group1[i],group1[j]));
  30. echo(str(group0[i]," >= ",group0[j], " = "),gte(group1[i],group1[j]));
  31. }
  32. }
  33. echo("----");
  34. echo("!");
  35. echo("! matrix ", !matrix_3x3);
  36. echo("! vector ", !vector);
  37. echo("----");
  38. echo("?:");
  39. echo("?: matrix ", matrix_3x3?true:false);
  40. echo("?: vextor ", vector?true:false);
  41. echo("----");
  42. cube();