Exemple #1
0
 /**
  * Returns the angle between the two vectors.
  *
  * @api
  * @param self $b The vector to compute the angle between.
  * @return float The angle between the two vectors in radians.
  * @throws Exception if either of the vectors are zero-length.
  * @throws Exception if the vectors are not in the same vector space.
  * @see self::_checkVectorSpace() For exception information.
  */
 public function angleBetween(self $b)
 {
     $denominator = $this->length() * $b->length();
     if ($denominator == 0) {
         throw new Exception('Cannot divide by zero');
     }
     return acos($this->dotProduct($b) / $denominator);
 }
Exemple #2
0
 /**
  * Verify that the length of the vector is correct.
  *
  * @test
  * @uses \Nubs\Vectorix\Vector::__construct
  * @uses \Nubs\Vectorix\Vector::components
  * @covers ::length
  */
 public function lengthIsCorrect()
 {
     $vector = new Vector([3, 4]);
     $this->assertEquals(5.0, $vector->length(), '', 1.0E-10);
 }