# Check if a point is inside of a triangle

**URL:** <https://discourse.processing.org/t/check-if-a-point-is-inside-of-a-triangle/34941>\
**Category:** Beginners\
**Created:** [February 2, 2022, 1:16pm UTC](https://discourse.processing.org/t/check-if-a-point-is-inside-of-a-triangle/34941 "2022-02-02T13:16:24Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![CodeMasterX](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/codemasterx/32/2942_2.png) [@CodeMasterX](https://discourse.processing.org/u/CodeMasterX)\
**Post date:** [February 2, 2022, 1:16pm UTC](https://discourse.processing.org/t/check-if-a-point-is-inside-of-a-triangle/34941/1 "2022-02-02T13:16:24Z")

</div>

Hi,  
how can I check if a point is inside of a triangle? Is there a mathematical formula for it?  
And what about any N sided shape?

And assuming this is true:  
 ![image](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/f/f14d7205e4cd0c3ac44294c8ecfadce607c45fd3.png)

Thank you!

---

<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:** [February 2, 2022, 1:30pm UTC](https://discourse.processing.org/t/check-if-a-point-is-inside-of-a-triangle/34941/2 "2022-02-02T13:30:28Z")

</div>

[JeffreyThompson.org/collision-detection/tri-point.php](http://jeffreythompson.org/collision-detection/tri-point.php)

---

<div class="post-metadata">

**Author:** ![CodeMasterX](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/codemasterx/32/2942_2.png) [@CodeMasterX](https://discourse.processing.org/u/CodeMasterX)\
**Post date:** [February 2, 2022, 2:58pm UTC](https://discourse.processing.org/t/check-if-a-point-is-inside-of-a-triangle/34941/3 "2022-02-02T14:58:44Z")

</div>

does this work with any shape? It should right?

---

<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:** [February 2, 2022, 3:05pm UTC](https://discourse.processing.org/t/check-if-a-point-is-inside-of-a-triangle/34941/4 "2022-02-02T15:05:25Z")

</div>

I didn’t test it, sorry. 😖

---

<div class="post-metadata">

**Author:** ![CodeMasterX](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/codemasterx/32/2942_2.png) [@CodeMasterX](https://discourse.processing.org/u/CodeMasterX)\
**Post date:** [February 2, 2022, 3:27pm UTC](https://discourse.processing.org/t/check-if-a-point-is-inside-of-a-triangle/34941/5 "2022-02-02T15:27:33Z")

</div>

It should. the only problem now is to sort the points to form a ring.
