/** * 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| }