Exemplo n.º 1
0
 /**
  * Project the vector onto another vector.
  *
  * @api
  * @param self $b The vector to project this vector onto.
  * @return self The vector projection of this vector onto $b.
  * @throws Exception if the vector length of $b is zero.
  * @throws Exception if the vectors are not in the same vector space.
  * @see self::_checkVectorSpace() For exception information.
  */
 public function projectOnto(self $b)
 {
     $bUnit = $b->normalize();
     return $bUnit->multiplyByScalar($this->dotProduct($bUnit));
 }
Exemplo n.º 2
0
 /**
  * Verify that normalization works.
  *
  * @test
  * @uses \Nubs\Vectorix\Vector::__construct
  * @uses \Nubs\Vectorix\Vector::components
  * @uses \Nubs\Vectorix\Vector::multiplyByScalar
  * @uses \Nubs\Vectorix\Vector::divideByScalar
  * @uses \Nubs\Vectorix\Vector::length
  * @covers ::normalize
  */
 public function normalizeSimpleVector()
 {
     $vector = new Vector([1, 1]);
     $resultComponents = $vector->normalize()->components();
     $this->assertEquals(sqrt(2) / 2, $resultComponents[0], '', 1.0E-10);
     $this->assertEquals(sqrt(2) / 2, $resultComponents[1], '', 1.0E-10);
 }