Is this the correct way to calculate the area of a triangle given the 3 triangle points/vertices? The vertices will never be negative values.
def triangle_area(tri):
x1, y1, x2, y2, x3, y3 = tri[0][0], tri[0][1], tri[1][0], tri[1][1], tri[2][0], tri[2][1]
return 0.5 * (((x2-x1)*(y3-y1))-((x3-x1)*(y2-y1)))
It is necessary to add abs to this formula to avoid negative area value (sign depends on orientation, not on positive/negative coordinates)
Yes, this formula is correct and it implements the best approach if you have vertices coordinates. It is based on cross product properties.
def triangle_area(tri):
x1, y1, x2, y2, x3, y3 = tri[0][0], tri[0][1], tri[1][0], tri[1][1], tri[2][0], tri[2][1]
return abs(0.5 * (((x2-x1)*(y3-y1))-((x3-x1)*(y2-y1))))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With