Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public function isInside(Vector3 $p){
- $v2 = new Vector2($p->x, $p->z);
- $hash = $this->hash($v2);
- if(isset($this->cache[$hash])){
- return $this->cache[$hash];
- }
- $intersects = 0;
- foreach($this->lines as $line){
- $intersects += $line->isAbsolutelyAbove($v2);
- }
- $this->cache[$hash] = $result = (bool) ($intersects & 1);
- return $result;
- }
- public function isAbsolutelyAbove(Vector2 $pt){
- $intercept = $this->getZInterceptByX($pt->x);
- if($intercept > $pt->y){
- return self::ABOVE;
- }
- if($intercept === $pt->y){
- return self::INTERSECT;
- }
- return self::BELOW;
- }
- public function getSlope(){
- return ($this->toz - $this->fromz) / ($this->tox - $this->fromx);
- }
- public function getZInterceptByX($x0){
- return $this->fromz - ($this->fromx - $x0) * $this->getSlope(); // c=mx-y
- }
Advertisement
Add Comment
Please, Sign In to add comment