示例#1
0
文件: main_02.php 项目: samiateber/42
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;