/** * 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; }
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"; echo "which is " . $r * 180.0 / M_PI . " degrees\n";
/** * Vector triple scalar product = v1 . (v2 x v3) * * @access public * @param object Math_Vector3 (or subclass) $v1 * @param object Math_Vector3 (or subclass) $v2 * @param object Math_Vector3 (or subclass) $v3 * @return mixed the triple scalar product (float) on success, a PEAR_Error object otherwise * * @see isVector3() * @see dotProduct() * @see crossProduct() */ function tripleScalarProduct($v1, $v2, $v3) { if (Math_VectorOp::isVector3($v1) && Math_VectorOp::isVector3($v2) && Math_VectorOp::isVector3($v3)) { return Math_VectorOp::dotProduct($v1, Math_VectorOp::crossProduct($v2, $v3)); } else { return PEAR_Error("All three vectors must be of the same type"); } }
/** * Vector triple scalar product = v1 . (v2 x v3) * * @param object Math_Vector3 (or subclass) $v1 * @param object Math_Vector3 (or subclass) $v2 * @param object Math_Vector3 (or subclass) $v3 * @return mixed the triple scalar product (float) on success * @throws InvalidArgumentException * * @see isVector3() * @see dotProduct() * @see crossProduct() */ public static function tripleScalarProduct($v1, $v2, $v3) { if (Math_VectorOp::isVector3($v1) && Math_VectorOp::isVector3($v2) && Math_VectorOp::isVector3($v3)) { return Math_VectorOp::dotProduct($v1, Math_VectorOp::crossProduct($v2, $v3)); } throw new InvalidArgumentException("All three vectors must be of the same type"); }