Math_Vector
[ class tree: Math_Vector ] [ index: Math_Vector ] [ all elements ]

Source for file vector_operations.php

Documentation is available at vector_operations.php

  1. <?php
  2.  
  3. require_once "Math/Vector/Vector.php";
  4. require_once "Math/Vector/Vector2.php";
  5. require_once "Math/Vector/Vector3.php";
  6. require_once "Math/Vector/VectorOp.php";
  7.  
  8. $v1 = new Math_Vector2(array(1,2));
  9. $v2 = new Math_Vector2(array(2,4));
  10.  
  11. $w1 = new Math_Vector3(array(2,3,1));
  12. $w2 = new Math_Vector3(array(1,-1,0));
  13. $w3 = new Math_Vector3(array(7,3,2));
  14.  
  15. echo date("Y-m-d H:i:s")."\n";
  16. echo "==\nVector v1: ".$v1->toString()."\n";
  17. echo "Vector v2: ".$v2->toString()."\n";
  18. $r Math_VectorOp::add($v1$v2);
  19. echo "v1 + v2: ".$r->toString()."\n";
  20. $r Math_VectorOp::substract($v1$v2);
  21. echo "v1 - v2: ".$r->toString()."\n";
  22. $r Math_VectorOp::multiply($v1$v2);
  23. echo "v1 * v2: ".$r->toString()."\n";
  24. $r Math_VectorOp::divide($v1$v2);
  25. echo "v1 / v2: ".$r->toString()."\n";
  26. echo "==\nVector w1: ".$w1->toString()."\n";
  27. echo "Vector w2: ".$w2->toString()."\n";
  28. echo "Vector w3: ".$w3->toString()."\n";
  29. $r Math_VectorOp::scale(2.0$w1);
  30. echo " 2.0 * w1 = ".$r->toString()."\n";
  31. $r Math_VectorOp::dotProduct($w1$w2);
  32. echo "w1 . w2 = $r\n";
  33. $r Math_VectorOp::crossProduct($w2$w3);
  34. echo "w2 x w3 = ".$r->toString()."\n";
  35. echo "The triple scalar product of 3 vectors is the volume
  36. of the parallelepiped defined by the vectors. Three coplanar
  37. vectors must give a volume of zero, w1, w2 and w3 are coplanar\n";
  38. $r Math_VectorOp::tripleScalarProduct($w1$w2$w3);
  39. echo "w1 . (w2 x w3) = $r\n";
  40. echo "Now we introduce z : ".$z->toString()."\n";
  41. echo "and z not being coplanar to w1, w2, or w3:\n";
  42. $r Math_VectorOp::tripleScalarProduct($z$w2$w3);
  43. echo "z * (w2 x w3) = $r\n";
  44. $r Math_VectorOp::angleBetween($z$w1);
  45. echo "and the angle between z and w1 is $r radians\n";
  46. echo "which is ".($r * 180.0/M_PI)." degrees\n";
  47.  
  48. ?>

Documentation generated on Mon, 11 Mar 2019 15:39:22 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.