# Check if a shape exists inside a complex shape

**URL:** <https://discourse.processing.org/t/check-if-a-shape-exists-inside-a-complex-shape/11176>\
**Category:** Coding Questions\
**Created:** [May 12, 2019, 4:55pm UTC](https://discourse.processing.org/t/check-if-a-shape-exists-inside-a-complex-shape/11176 "2019-05-12T16:55:24Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Alisha](https://avatars.discourse-cdn.com/v4/letter/a/e9c0ed/32.png) [@Alisha](https://discourse.processing.org/u/Alisha)\
**Post date:** [May 12, 2019, 4:55pm UTC](https://discourse.processing.org/t/check-if-a-shape-exists-inside-a-complex-shape/11176/1 "2019-05-12T16:55:24Z")

</div>

I have a custom shape, which I made using:

```
        beginShape(LINES);
        vertex(190, 231);
        vertex(203, 143);
        vertex(203, 143);
        vertex(298, 153);
        vertex(298, 153);
        vertex(365, 231);
        vertex(365, 231);
        vertex(365, 413);
        vertex(365, 413);
        vertex(251, 413);
        vertex(251, 413);
        vertex(190, 231);
        endShape();

```

 ![50%20am](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/f/f52774bf2f02256439e598bffaa3c9f5718d11bc.png)

I want to check if this ellipse is inside the perimeter of this custom shape. I tried to search online and the docs but couldn’t find anything. Also, I am new to P5.js

Any help would be greatly appreciated.

Thanks.

---

<div class="post-metadata">

**Author:** ![josephh](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/josephh/32/210_2.png) [@josephh](https://discourse.processing.org/u/josephh)\
**Post date:** [May 12, 2019, 9:40pm UTC](https://discourse.processing.org/t/check-if-a-shape-exists-inside-a-complex-shape/11176/2 "2019-05-12T21:40:00Z")

</div>

Hi,

You might want to check this link :

> <https://gamedev.stackexchange.com/questions/84029/algorithm-to-verify-if-a-shape-is-inside-another>

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [May 13, 2019, 8:15am UTC](https://discourse.processing.org/t/check-if-a-shape-exists-inside-a-complex-shape/11176/3 "2019-05-13T08:15:11Z")

</div>

You could give the shape a pale color

Then with get() check the color getColor

If it’s == shapeCol you are inside the shape

This works also with an offscreen PGraphics which allows to not use a fill color on the visible screen

---

<div class="post-metadata">

**Author:** ![jeremydouglass](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jeremydouglass/32/20_2.png) [@jeremydouglass](https://discourse.processing.org/u/jeremydouglass)\
**Post date:** [May 19, 2019, 6:19am UTC](https://discourse.processing.org/t/check-if-a-shape-exists-inside-a-complex-shape/11176/4 "2019-05-19T06:19:43Z")

</div>

Here is an interactive demo of Polygon-Circle collision detection:

> **[Collision Detection](http://www.jeffreythompson.org/collision-detection/poly-circle.php)**
>
> An online book about collision detection using Processing.

This example is Processing, not p5.js, but the solution is almost identical.

---

<div class="post-metadata">

**Author:** ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)\
**Post date:** [May 19, 2019, 6:43am UTC](https://discourse.processing.org/t/check-if-a-shape-exists-inside-a-complex-shape/11176/5 "2019-05-19T06:43:05Z")

</div>

> [@jeremydouglass](#):
>
> This example is Processing, not p5.js,

[CrHallberg.com/CollisionDetection/Website/poly-circle.html](http://CrHallberg.com/CollisionDetection/Website/poly-circle.html)
