pocketmine\math\Vector3::subtract PHP Method

subtract() public method

public subtract ( Vector3 | integer $x, integer $y, integer $z ) : Vector3
$x Vector3 | integer
$y integer
$z integer
return Vector3
    public function subtract($x = 0, $y = 0, $z = 0)
    {
        if ($x instanceof Vector3) {
            return $this->add(-$x->x, -$x->y, -$x->z);
        } else {
            return $this->add(-$x, -$y, -$z);
        }
    }

Usage Example

 /**
  * Checks whether the passed {@link Vector3} is included in this {@link Space}.<br>
  * Floating point vectors are accepted.<br>
  * <br>
  * The contents of this function are based on <a
  * href="http://mathworld.wolfram.com/Point-LineDistance3-Dimensional.html">Wolfram|MathWorld: Point-Lne Distance
  * (3-Dimensional)</a>, whereas {@code X0 = $v, X1 = $this->baseCenter, X2 = $this->topCenter}.
  *
  * @param Vector3 $v the coordinates to check.
  *
  * @return bool whether <code> $v</code> is inside the space.
  */
 public function isInside(Vector3 $v)
 {
     if (!$this->isValid()) {
         return false;
     }
     if ($v instanceof Position and $v->getLevel()->getName() !== $this->levelName) {
         return false;
     }
     $distSquared = $v->subtract($this->baseCenter)->cross($v->subtract($this->topCenter))->lengthSquared() / $this->topCenter->subtract($this->baseCenter)->lengthSquared();
     // |---|
     return $distSquared <= $this->radiusSquared;
     // |(X0 - X1) x (X0 - X2)| / |X2 - X1|
 }