I don't fully understand how it's related to the triangular area of three given 2D Cartesian points on a 2D plane. I do know that given the three points as:
X = (4, 0)
Y = (0, 0)
Z = (0, 3)
The function returns twice the size of the expected triangular area the three points have marked.
Here's the function I found on a blog:
inline float triarea2(const float* a, const float* b, const float* c)
{
const float ax = b[0] - a[0];
const float ay = b[1] - a[1];
const float bx = c[0] - a[0];
const float by = c[1] - a[1];
return bx*ay - ax*by;
}
Or in Java code:
public static float triarea2(float[] a, float[] b, float[] c)
{
float ax = b[0] - a[0];
float ay = b[1] - a[1];
float bx = c[0] - a[0];
float by = c[1] - a[1];
return bx * ay - ax * by;
}
Can someone help me explain what this function does, and how one can come up with such math? How do one derive the area from a simple triangle? Thanks.