Ejemplo n.º 1
0
 /**
  * @dataProvider dataProviderForCrossProductExceptionWrongSize
  */
 public function testCrossProductExceptionWrongSize(array $A, array $B)
 {
     $A = new Vector($A);
     $B = new Vector($B);
     $this->setExpectedException('MathPHP\\Exception\\VectorException');
     $A->crossProduct($B);
 }
Ejemplo n.º 2
0
 public function Program()
 {
     $a = array(3, 4, 5);
     $b = array(4, 3, 5);
     $c = array(-5, -12, -13);
     $va = new Vector($a);
     $vb = new Vector($b);
     $vc = new Vector($c);
     $result1 = Vector::dotProduct($va, $vb);
     $result2 = Vector::crossProduct($va, $vb)->getValues();
     $result3 = Vector::scalarTripleProduct($va, $vb, $vc);
     $result4 = Vector::vectorTrippleProduct($va, $vb, $vc)->getValues();
     printf("\n");
     printf("A = (%0.2f, %0.2f, %0.2f)\n", $a[0], $a[1], $a[2]);
     printf("B = (%0.2f, %0.2f, %0.2f)\n", $b[0], $b[1], $b[2]);
     printf("C = (%0.2f, %0.2f, %0.2f)\n", $c[0], $c[1], $c[2]);
     printf("\n");
     printf("A · B = %0.2f\n", $result1);
     printf("A × B = (%0.2f, %0.2f, %0.2f)\n", $result2[0], $result2[1], $result2[2]);
     printf("A · (B × C) = %0.2f\n", $result3);
     printf("A × (B × C) =(%0.2f, %0.2f, %0.2f)\n", $result4[0], $result4[1], $result4[2]);
 }
Ejemplo n.º 3
0
Vector::$verbose = True;
$vtxO = new Vertex(array('x' => 0.0, 'y' => 0.0, 'z' => 0.0));
$vtxX = new Vertex(array('x' => 1.0, 'y' => 0.0, 'z' => 0.0));
$vtxY = new Vertex(array('x' => 0.0, 'y' => 1.0, 'z' => 0.0));
$vtxZ = new Vertex(array('x' => 0.0, 'y' => 0.0, 'z' => 1.0));
$vtcXunit = new Vector(array('orig' => $vtxO, 'dest' => $vtxX));
$vtcYunit = new Vector(array('orig' => $vtxO, 'dest' => $vtxY));
$vtcZunit = new Vector(array('orig' => $vtxO, 'dest' => $vtxZ));
print $vtcXunit . PHP_EOL;
print $vtcYunit . PHP_EOL;
print $vtcZunit . PHP_EOL;
$dest1 = new Vertex(array('x' => -12.34, 'y' => 23.45, 'z' => -34.56));
Vertex::$verbose = True;
$vtc1 = new Vector(array('dest' => $dest1));
Vertex::$verbose = False;
$orig2 = new Vertex(array('x' => 23.87, 'y' => -37.95, 'z' => 78.34));
$dest2 = new Vertex(array('x' => -12.34, 'y' => 23.45, 'z' => -34.56));
$vtc2 = new Vector(array('orig' => $orig2, 'dest' => $dest2));
print 'Magnitude is ' . $vtc2->magnitude() . PHP_EOL;
$nVtc2 = $vtc2->normalize();
print 'Normalized $vtc2 is ' . $nVtc2 . PHP_EOL;
print 'Normalized $vtc2 magnitude is ' . $nVtc2->magnitude() . PHP_EOL;
print '$vtc1 + $vtc2 is ' . $vtc1->add($vtc2) . PHP_EOL;
print '$vtc1 - $vtc2 is ' . $vtc1->sub($vtc2) . PHP_EOL;
print 'opposite of $vtc1 is ' . $vtc1->opposite() . PHP_EOL;
print 'scalar product of $vtc1 and 42 is ' . $vtc1->scalarProduct(42) . PHP_EOL;
print 'dot product of $vtc1 and $vtc2 is ' . $vtc1->dotProduct($vtc2) . PHP_EOL;
print 'cross product of $vtc1 and $vtc2 is ' . $vtc1->crossProduct($vtc2) . PHP_EOL;
print 'cross product of $vtcXunit and $vtcYunit is ' . $vtcXunit->crossProduct($vtcYunit) . 'aka $vtcZunit' . PHP_EOL;
print 'cosinus of angle between $vtc1 and $vtc2 is ' . $vtc1->cos($vtc2) . PHP_EOL;
print 'cosinus of angle between $vtcXunit and $vtcYunit is ' . $vtcXunit->cos($vtcYunit) . PHP_EOL;
Ejemplo n.º 4
0
 /**
  * Axiom: A x (B x C) = (A ⋅ C)B - (A ⋅ B)C
  * Lagrange's formula
  * @dataProvider dataProviderForCrossProductThreeVectors
  */
 public function testCrossProductLagrangeFormula(array $A, array $B, array $C)
 {
     $A = new Vector($A);
     $B = new Vector($B);
     $C = new Vector($C);
     $Ax⟮BxC⟯ = $A->crossProduct($B->crossProduct($C));
     $⟮A⋅C⟯B = $B->scalarMultiply($A->dotProduct($C));
     $⟮A⋅B⟯C = $C->scalarMultiply($A->dotProduct($B));
     $⟮A⋅C⟯B−⟮A⋅B⟯C = $⟮A⋅C⟯B->subtract($⟮A⋅B⟯C);
     $this->assertEquals($Ax⟮BxC⟯, $⟮A⋅C⟯B−⟮A⋅B⟯C);
     $this->assertEquals($Ax⟮BxC⟯->getVector(), $⟮A⋅C⟯B−⟮A⋅B⟯C->getVector());
 }
Ejemplo n.º 5
0
 /**
  * @covers webd\vectors\Vector::crossProduct
  */
 public function testCrossProduct()
 {
     $other = new Vector(4, 5, 6);
     $r = $this->object->crossProduct($other);
     $this->assertEquals(array(-3, 6, -3), $r->getValue());
 }
Ejemplo n.º 6
0
 /**
  * Computes the vector triple product of three vectors.
  *
  * @param Vector $b The second vector of the triple product.
  * @param Vector $c The third vector of the triple product.
  * @return Vector The vector triple product of the three vectors.
  * @throws \Exception if the vectors are not 3-dimensional.
  * @throws \Exception if the vectors are not in the same vector space.
  * @see checkVectorSpace() For Exception information.
  */
 public function vectorTripleProduct(Vector $b, Vector $c)
 {
     return $this->crossProduct($b->crossProduct($c));
 }