public function testDotProductExceptionSizeDifference() { $A = new Vector([1, 2]); $B = new Vector([1, 2, 3]); $this->setExpectedException('MathPHP\\Exception\\VectorException'); $A->dotProduct($B); }
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]); }
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;
/** * Axiom: A⋅A⊥ = -A⊥⋅A * Swapping operands changes the sign of the perp dot product * @dataProvider dataProviderForPerpendicularIdentity */ public function testPerpDotProdcutSwapOperandsChangeSign(array $A) { $A = new Vector($A); $A⊥ = $A->perpendicular(); $A⋅A⊥ = $A->dotProduct($A⊥); $A⊥⋅A = $A⊥->dotProduct($A); $this->assertEquals($A⋅A⊥, -$A⊥⋅A); }
/** * @covers webd\vectors\Vector::dotProduct */ public function testDotProduct() { $this->assertEquals(14, $this->object->dotProduct($this->object)); }