Skip to main content
updated image to more clearly show restrictions on alpha, beta, gamma to be inside triangle
Source Link
bobobobo
  • 9.8k
  • 21
  • 76
  • 91

You can find if a point is in a triangle using barycentric coordinates.

If you have a triangle with vertices $A$, $B$ & $C$, & a point P in the plane of the triangle, you simply need to find:

$ AreaABC = \frac{ \left| \overline{AB} \times \overline{AC} \right| }{ 2 } $$AreaABC = \frac{ \left| \overline{AB} \times \overline{AC} \right| }{ 2 }$

$ \alpha = \frac{ \left| \overline{PB} \times \overline{PC} \right| }{ 2AreaABC } $$\alpha = \frac{ \left| \overline{PB} \times \overline{PC} \right| }{ 2AreaABC }$

$ \beta = \frac{ \left| \overline{PC} \times \overline{PA} \right| }{ 2AreaABC } $$\beta = \frac{ \left| \overline{PC} \times \overline{PA} \right| }{ 2AreaABC }$

$ \gamma = 1 − \alpha − \beta $$\gamma = 1 − \alpha − \beta$

Here $\alpha$ is the ratio of the area of a subtriangle $PBC$ over the area of the whole triangle $ABC$, as shown in this image from Peter Shirley's book:

finding barycentric coordinates

If ALL of the following 4 restrictions are met:

  • $ 0 \le \alpha \le 1 $
  • $ 0 \le \beta \le 1 $
  • $ 0 \le \gamma \le 1 $
  • $\alpha + \beta + \gamma = 1$

then the point P is inside the triangle.

If ANY of $\alpha$,$\beta$,$\gamma$ are outside those ranges, or if the sum of $ \alpha + \beta + \gamma \ne 1 $ then the point P is not inside the triangle.

Notice how we exploit the 4th condition ($\alpha + \beta + \gamma = 1$) in finding $\gamma$.

Even though we find $\gamma$ that way, we still must check that $ 0 \le \alpha \le 1 $ and $ 0 \le \beta \le 1 $ and $ 0 \le \gamma \le 1 $ for the point to be inside the triangle.

$\gamma$ can easily be outside $[0, 1]$. Say $\alpha=0.99$ and $\beta=0.85$. Then $\gamma = 1 - 0.99 - 0.85 = -0.84$, and the point that got us those barycentric coordinates would be outside the triangle.

Things to observe:

  • When one of ($\alpha$, $\beta$, $\gamma$) is 1 and the other two are 0, then the point P is exactly at a vertex of the triangle.

  • When one of ($\alpha$, $\beta$, $\gamma$) is 0, and the other 2 coordinates are between 0 and 1, the point P is on an edge of the triangle.

You can find if a point is in a triangle using barycentric coordinates.

If you have a triangle with vertices $A$, $B$ & $C$, & a point P in the plane of the triangle, you simply need to find:

$ AreaABC = \frac{ \left| \overline{AB} \times \overline{AC} \right| }{ 2 } $

$ \alpha = \frac{ \left| \overline{PB} \times \overline{PC} \right| }{ 2AreaABC } $

$ \beta = \frac{ \left| \overline{PC} \times \overline{PA} \right| }{ 2AreaABC } $

$ \gamma = 1 − \alpha − \beta $

Here $\alpha$ is the ratio of the area of a subtriangle $PBC$ over the area of the whole triangle $ABC$, as shown in this image from Peter Shirley's book:

finding barycentric coordinates

If ALL of the following 4 restrictions are met:

  • $ 0 \le \alpha \le 1 $
  • $ 0 \le \beta \le 1 $
  • $ 0 \le \gamma \le 1 $
  • $\alpha + \beta + \gamma = 1$

then the point P is inside the triangle.

If ANY of $\alpha$,$\beta$,$\gamma$ are outside those ranges, or if the sum of $ \alpha + \beta + \gamma \ne 1 $ then the point P is not inside the triangle.

Notice how we exploit the 4th condition ($\alpha + \beta + \gamma = 1$) in finding $\gamma$.

Even though we find $\gamma$ that way, we still must check that $ 0 \le \alpha \le 1 $ and $ 0 \le \beta \le 1 $ and $ 0 \le \gamma \le 1 $ for the point to be inside the triangle.

$\gamma$ can easily be outside $[0, 1]$. Say $\alpha=0.99$ and $\beta=0.85$. Then $\gamma = 1 - 0.99 - 0.85 = -0.84$, and the point that got us those barycentric coordinates would be outside the triangle.

Things to observe:

  • When one of ($\alpha$, $\beta$, $\gamma$) is 1 and the other two are 0, then the point P is exactly at a vertex of the triangle.

  • When one of ($\alpha$, $\beta$, $\gamma$) is 0, and the other 2 coordinates are between 0 and 1, the point P is on an edge of the triangle.

You can find if a point is in a triangle using barycentric coordinates.

If you have a triangle with vertices $A$, $B$ & $C$, & a point P in the plane of the triangle, you simply need to find:

$AreaABC = \frac{ \left| \overline{AB} \times \overline{AC} \right| }{ 2 }$

$\alpha = \frac{ \left| \overline{PB} \times \overline{PC} \right| }{ 2AreaABC }$

$\beta = \frac{ \left| \overline{PC} \times \overline{PA} \right| }{ 2AreaABC }$

$\gamma = 1 − \alpha − \beta$

Here $\alpha$ is the ratio of the area of a subtriangle $PBC$ over the area of the whole triangle $ABC$, as shown in this image from Peter Shirley's book:

finding barycentric coordinates

If ALL of the following 4 restrictions are met:

  • $ 0 \le \alpha \le 1 $
  • $ 0 \le \beta \le 1 $
  • $ 0 \le \gamma \le 1 $
  • $\alpha + \beta + \gamma = 1$

then the point P is inside the triangle.

If ANY of $\alpha$,$\beta$,$\gamma$ are outside those ranges, or if the sum of $ \alpha + \beta + \gamma \ne 1 $ then the point P is not inside the triangle.

Notice how we exploit the 4th condition ($\alpha + \beta + \gamma = 1$) in finding $\gamma$.

Even though we find $\gamma$ that way, we still must check that $ 0 \le \alpha \le 1 $ and $ 0 \le \beta \le 1 $ and $ 0 \le \gamma \le 1 $ for the point to be inside the triangle.

$\gamma$ can easily be outside $[0, 1]$. Say $\alpha=0.99$ and $\beta=0.85$. Then $\gamma = 1 - 0.99 - 0.85 = -0.84$, and the point that got us those barycentric coordinates would be outside the triangle.

Things to observe:

  • When one of ($\alpha$, $\beta$, $\gamma$) is 1 and the other two are 0, then the point P is exactly at a vertex of the triangle.

  • When one of ($\alpha$, $\beta$, $\gamma$) is 0, and the other 2 coordinates are between 0 and 1, the point P is on an edge of the triangle.

updated image to more clearly show restrictions on alpha, beta, gamma to be inside triangle
Source Link
bobobobo
  • 9.8k
  • 21
  • 76
  • 91

A common technique inYou can find if a computer programpoint is to usein a triangle using barycentric coordinates.

Barycentric coordinates are a lot easier to find than any web resources indicate, so I'm not linking to them.

The easiest way to obtain barycentric coordinates of a point P, givenIf you have a triangle with vertices described by the vectors A$A$, B$B$ & $C$, C is likely this method& a point P in the plane of the triangle, you simply need to find:

$ AreaABC = \frac{ \left| \overline{AB} \times \overline{AC} \right| }{ 2 } $

$ \alpha = \frac{ \left| \overline{PB} \times \overline{PC} \right| }{ 2AreaABC } $

$ \beta = \frac{ \left| \overline{PC} \times \overline{PA} \right| }{ 2AreaABC } $

$ \gamma = 1 − \alpha − \beta $

Here $\alpha$ is the ratio of the area of a subtriangle PBC$PBC$ over the area of the whole triangle ABC$ABC$, as shown in this image from Peter Shirley's book:

how to find barycentric coordinatesfinding barycentric coordinates

If ALLALL of the following 4 restrictions are met:

  • $ 0 \le \alpha \le 1 $
  • $ 0 \le \beta \le 1 $
  • $ 0 \le \gamma \le 1 $
  • $\alpha + \beta + \gamma = 1$

then the point P is inside the triangle.

If ANY of $\alpha$,$\beta$,$\gamma$ are outside those ranges, or if the sum of $ \alpha + \beta + \gamma \ne 1 $ then the point P is not inside the triangle.

Note also when one of $\alpha$,$\beta$,$\gamma$ is 0, and the other 2 coordinates are between 0 and 1,Notice how we exploit the point4th condition P is on an edge of the triangle($\alpha + \beta + \gamma = 1$) in finding $\gamma$.

When one ofEven though we find $\alpha$,$\beta$,$\gamma$ is 1 and the other two arethat way, we 0still must check, then that $ 0 \le \alpha \le 1 $ and $ 0 \le \beta \le 1 $ and $ 0 \le \gamma \le 1 $ for the point P is exactly at a vertex ofto be inside the triangle.

$\gamma$ can easily be outside $[0, 1]$. Say $\alpha=0.99$ and $\beta=0.85$. Then $\gamma = 1 - 0.99 - 0.85 = -0.84$, and the point that got us those barycentric coordinates would be outside the triangle.

Of course, these computations assume P is already in the plane of the triangle. If P is not in the plane of the triangle, then you should project it there first, before computing the barycentric coordinates.Things to observe:

  • When one of ($\alpha$, $\beta$, $\gamma$) is 1 and the other two are 0, then the point P is exactly at a vertex of the triangle.

  • When one of ($\alpha$, $\beta$, $\gamma$) is 0, and the other 2 coordinates are between 0 and 1, the point P is on an edge of the triangle.

A common technique in a computer program is to use barycentric coordinates.

Barycentric coordinates are a lot easier to find than any web resources indicate, so I'm not linking to them.

The easiest way to obtain barycentric coordinates of a point P, given a triangle with vertices described by the vectors A, B, C is likely this method:

$ AreaABC = \frac{ \left| \overline{AB} \times \overline{AC} \right| }{ 2 } $

$ \alpha = \frac{ \left| \overline{PB} \times \overline{PC} \right| }{ 2AreaABC } $

$ \beta = \frac{ \left| \overline{PC} \times \overline{PA} \right| }{ 2AreaABC } $

$ \gamma = 1 − \alpha − \beta $

Here $\alpha$ is the ratio of the area of a subtriangle PBC over the area of the whole triangle ABC, as shown in this image from Peter Shirley's book:

how to find barycentric coordinates

If ALL of the following 4 restrictions are met:

  • $ 0 \le \alpha \le 1 $
  • $ 0 \le \beta \le 1 $
  • $ 0 \le \gamma \le 1 $
  • $\alpha + \beta + \gamma = 1$

then the point P is inside the triangle.

If ANY of $\alpha$,$\beta$,$\gamma$ are outside those ranges, or if the sum of $ \alpha + \beta + \gamma \ne 1 $ then the point P is not inside the triangle.

Note also when one of $\alpha$,$\beta$,$\gamma$ is 0, and the other 2 coordinates are between 0 and 1, the point P is on an edge of the triangle.

When one of $\alpha$,$\beta$,$\gamma$ is 1 and the other two are 0, then the point P is exactly at a vertex of the triangle.

Of course, these computations assume P is already in the plane of the triangle. If P is not in the plane of the triangle, then you should project it there first, before computing the barycentric coordinates.

You can find if a point is in a triangle using barycentric coordinates.

If you have a triangle with vertices $A$, $B$ & $C$, & a point P in the plane of the triangle, you simply need to find:

$ AreaABC = \frac{ \left| \overline{AB} \times \overline{AC} \right| }{ 2 } $

$ \alpha = \frac{ \left| \overline{PB} \times \overline{PC} \right| }{ 2AreaABC } $

$ \beta = \frac{ \left| \overline{PC} \times \overline{PA} \right| }{ 2AreaABC } $

$ \gamma = 1 − \alpha − \beta $

Here $\alpha$ is the ratio of the area of a subtriangle $PBC$ over the area of the whole triangle $ABC$, as shown in this image from Peter Shirley's book:

finding barycentric coordinates

If ALL of the following 4 restrictions are met:

  • $ 0 \le \alpha \le 1 $
  • $ 0 \le \beta \le 1 $
  • $ 0 \le \gamma \le 1 $
  • $\alpha + \beta + \gamma = 1$

then the point P is inside the triangle.

If ANY of $\alpha$,$\beta$,$\gamma$ are outside those ranges, or if the sum of $ \alpha + \beta + \gamma \ne 1 $ then the point P is not inside the triangle.

Notice how we exploit the 4th condition ($\alpha + \beta + \gamma = 1$) in finding $\gamma$.

Even though we find $\gamma$ that way, we still must check that $ 0 \le \alpha \le 1 $ and $ 0 \le \beta \le 1 $ and $ 0 \le \gamma \le 1 $ for the point to be inside the triangle.

$\gamma$ can easily be outside $[0, 1]$. Say $\alpha=0.99$ and $\beta=0.85$. Then $\gamma = 1 - 0.99 - 0.85 = -0.84$, and the point that got us those barycentric coordinates would be outside the triangle.

Things to observe:

  • When one of ($\alpha$, $\beta$, $\gamma$) is 1 and the other two are 0, then the point P is exactly at a vertex of the triangle.

  • When one of ($\alpha$, $\beta$, $\gamma$) is 0, and the other 2 coordinates are between 0 and 1, the point P is on an edge of the triangle.

using the full formula to compute \gamma is not efficient. the answer clearly states the restriction on \alpha, \beta & \gamma for the point to be inside the triangle
Source Link
bobobobo
  • 9.8k
  • 21
  • 76
  • 91

A common technique in a computer program is to use barycentric coordinates.

Barycentric coordinates are a lot easier to find than any web resources indicate, so I'm not linking to them.

The easiest way to obtain barycentric coordinates of a point P, given a triangle with vertices described by the vectors A, B, C is likely this method:

$ AreaABC = \frac{ \left| \overline{AB} \times \overline{AC} \right| }{ 2 } $

$ \alpha = \frac{ \left| \overline{PB} \times \overline{PC} \right| }{ 2AreaABC } $

$ \beta = \frac{ \left| \overline{PC} \times \overline{PA} \right| }{ 2AreaABC } $

$ \gamma= \frac{ \left| \overline{PB} \times \overline{PA} \right| }{ 2AreaABC } $$ \gamma = 1 − \alpha − \beta $

Here $\alpha$ is the ratio of the area of a subtriangle PBC over the area of the whole triangle ABC, as shown in this image from Peter Shirley's book:

how to find barycentric coordinates

If ALL of the following 4 restrictions are met:

  • $ 0 \le \alpha \le 1 $
  • $ 0 \le \beta \le 1 $
  • $ 0 \le \gamma \le 1 $
  • $\alpha + \beta + \gamma = 1$

then the point P is inside the triangle.

If ANY of $\alpha$,$\beta$,$\gamma$ are outside those ranges, or if the sum of $ \alpha + \beta + \gamma \ne 1 $ then the point P is not inside the triangle.

Note also when one of $\alpha$,$\beta$,$\gamma$ is 0, and the other 2 coordinates are between 0 and 1, the point P is on an edge of the triangle.

When one of $\alpha$,$\beta$,$\gamma$ is 1 and the other two are 0, then the point P is exactly at a vertex of the triangle.

Of course, these computations assume P is already in the plane of the triangle. If P is not in the plane of the triangle, then you should project it there first, before computing the barycentric coordinates.

A common technique in a computer program is to use barycentric coordinates.

Barycentric coordinates are a lot easier to find than any web resources indicate, so I'm not linking to them.

The easiest way to obtain barycentric coordinates of a point P, given a triangle with vertices described by the vectors A, B, C is likely this method:

$ AreaABC = \frac{ \left| \overline{AB} \times \overline{AC} \right| }{ 2 } $

$ \alpha = \frac{ \left| \overline{PB} \times \overline{PC} \right| }{ 2AreaABC } $

$ \beta = \frac{ \left| \overline{PC} \times \overline{PA} \right| }{ 2AreaABC } $

$ \gamma= \frac{ \left| \overline{PB} \times \overline{PA} \right| }{ 2AreaABC } $

Here $\alpha$ is the ratio of the area of a subtriangle PBC over the area of the whole triangle ABC, as shown in this image from Peter Shirley's book:

how to find barycentric coordinates

If ALL of the following 4 restrictions are met:

  • $ 0 \le \alpha \le 1 $
  • $ 0 \le \beta \le 1 $
  • $ 0 \le \gamma \le 1 $
  • $\alpha + \beta + \gamma = 1$

then the point P is inside the triangle.

If ANY of $\alpha$,$\beta$,$\gamma$ are outside those ranges, or if the sum of $ \alpha + \beta + \gamma \ne 1 $ then the point P is not inside the triangle.

Note also when one of $\alpha$,$\beta$,$\gamma$ is 0, and the other 2 coordinates are between 0 and 1, the point P is on an edge of the triangle.

When one of $\alpha$,$\beta$,$\gamma$ is 1 and the other two are 0, then the point P is exactly at a vertex of the triangle.

Of course, these computations assume P is already in the plane of the triangle. If P is not in the plane of the triangle, then you should project it there first, before computing the barycentric coordinates.

A common technique in a computer program is to use barycentric coordinates.

Barycentric coordinates are a lot easier to find than any web resources indicate, so I'm not linking to them.

The easiest way to obtain barycentric coordinates of a point P, given a triangle with vertices described by the vectors A, B, C is likely this method:

$ AreaABC = \frac{ \left| \overline{AB} \times \overline{AC} \right| }{ 2 } $

$ \alpha = \frac{ \left| \overline{PB} \times \overline{PC} \right| }{ 2AreaABC } $

$ \beta = \frac{ \left| \overline{PC} \times \overline{PA} \right| }{ 2AreaABC } $

$ \gamma = 1 − \alpha − \beta $

Here $\alpha$ is the ratio of the area of a subtriangle PBC over the area of the whole triangle ABC, as shown in this image from Peter Shirley's book:

how to find barycentric coordinates

If ALL of the following 4 restrictions are met:

  • $ 0 \le \alpha \le 1 $
  • $ 0 \le \beta \le 1 $
  • $ 0 \le \gamma \le 1 $
  • $\alpha + \beta + \gamma = 1$

then the point P is inside the triangle.

If ANY of $\alpha$,$\beta$,$\gamma$ are outside those ranges, or if the sum of $ \alpha + \beta + \gamma \ne 1 $ then the point P is not inside the triangle.

Note also when one of $\alpha$,$\beta$,$\gamma$ is 0, and the other 2 coordinates are between 0 and 1, the point P is on an edge of the triangle.

When one of $\alpha$,$\beta$,$\gamma$ is 1 and the other two are 0, then the point P is exactly at a vertex of the triangle.

Of course, these computations assume P is already in the plane of the triangle. If P is not in the plane of the triangle, then you should project it there first, before computing the barycentric coordinates.

The computation of gamma is wrong. As noted by user yyny on Oct 24, 2018. You can't use shortcut author proposes to calculate gamma.
Source Link
Loading
Include note that $\alpha + \beta + \gamma = 1$
Source Link
bobobobo
  • 9.8k
  • 21
  • 76
  • 91
Loading
Include note that $\alpha + \beta + \gamma = 1$
Source Link
bobobobo
  • 9.8k
  • 21
  • 76
  • 91
Loading
Include note that $\alpha + \beta + \gamma = 1$
Source Link
bobobobo
  • 9.8k
  • 21
  • 76
  • 91
Loading
deleted 6 characters in body
Source Link
bobobobo
  • 9.8k
  • 21
  • 76
  • 91
Loading
added 208 characters in body
Source Link
bobobobo
  • 9.8k
  • 21
  • 76
  • 91
Loading
Source Link
bobobobo
  • 9.8k
  • 21
  • 76
  • 91
Loading