예제 #1
0
 /**
  * Calculates the point vector which is positioned exactly in the center of the face
  * this is accomplished by calculating the average of all vertex-pointvectors
  */
 private function calculateCenter()
 {
     $center = new \Math_Vector3(array(0, 0, 0));
     foreach ($this->vertexes as $vertex) {
         $center = new \Math_Vector3(\Math_VectorOp::add($center, $vertex)->getTuple());
     }
     $center = new \Math_Vector3(\Math_VectorOp::scale(1 / count($this->vertexes), $center)->getTuple());
     return $center;
 }
예제 #2
0
 /**
  * Calculates the intersection point bnetween the current and two other planes
  *
  * @param Plane $plane1
  * @param Plane $plane2
  * @return bool|\Math_Vector3
  * @throws InvalidArgumentException
  */
 public function calculateIntersectionPointWithTwoPlanes(self $plane1, self $plane2)
 {
     $n1 = $this->normalVectorNormalized;
     $n2 = $plane1->normalVectorNormalized;
     $n3 = $plane2->normalVectorNormalized;
     $d1 = $this->distanceToOrigin;
     $d2 = $plane1->distanceToOrigin;
     $d3 = $plane2->distanceToOrigin;
     $n2_x_n3 = \Math_VectorOp::crossProduct($n2, $n3);
     $n3_x_n1 = \Math_VectorOp::crossProduct($n3, $n1);
     $n1_x_n2 = \Math_VectorOp::crossProduct($n1, $n2);
     $p = new \Math_Vector3(\Math_VectorOp::add(\Math_VectorOp::add(\Math_VectorOp::scale($d1, $n2_x_n3), \Math_VectorOp::scale($d2, $n3_x_n1)), \Math_VectorOp::scale($d3, $n1_x_n2))->getTuple());
     $divisor = \Math_VectorOp::dotProduct($n1, $n2_x_n3);
     if ((double) 0 === $divisor) {
         throw new \InvalidArgumentException('no point-intersection');
     }
     $p->scale(1 / $divisor);
     return $p;
 }
$w3 = new Math_Vector3(array(7, 3, 2));
echo date("Y-m-d H:i:s") . "\n";
echo "==\nVector v1: " . $v1->toString() . "\n";
echo "Vector v2: " . $v2->toString() . "\n";
$r = Math_VectorOp::add($v1, $v2);
echo "v1 + v2: " . $r->toString() . "\n";
$r = Math_VectorOp::substract($v1, $v2);
echo "v1 - v2: " . $r->toString() . "\n";
$r = Math_VectorOp::multiply($v1, $v2);
echo "v1 * v2: " . $r->toString() . "\n";
$r = Math_VectorOp::divide($v1, $v2);
echo "v1 / v2: " . $r->toString() . "\n";
echo "==\nVector w1: " . $w1->toString() . "\n";
echo "Vector w2: " . $w2->toString() . "\n";
echo "Vector w3: " . $w3->toString() . "\n";
$r = Math_VectorOp::scale(2.0, $w1);
echo " 2.0 * w1 = " . $r->toString() . "\n";
$r = Math_VectorOp::dotProduct($w1, $w2);
echo "w1 . w2 = {$r}\n";
$r = Math_VectorOp::crossProduct($w2, $w3);
echo "w2 x w3 = " . $r->toString() . "\n";
echo "The triple scalar product of 3 vectors is the volume\r\nof the parallelepiped defined by the vectors. Three coplanar\r\nvectors must give a volume of zero, w1, w2 and w3 are coplanar\n";
$r = Math_VectorOp::tripleScalarProduct($w1, $w2, $w3);
echo "w1 . (w2 x w3) = {$r}\n";
$z = Math_VectorOp::createOne(3);
echo "Now we introduce z : " . $z->toString() . "\n";
echo "and z not being coplanar to w1, w2, or w3:\n";
$r = Math_VectorOp::tripleScalarProduct($z, $w2, $w3);
echo "z * (w2 x w3) = {$r}\n";
$r = Math_VectorOp::angleBetween($z, $w1);
echo "and the angle between z and w1 is {$r} radians\n";