1

I looked up calculating the area of triangle given three vertices.

func calculate_area_of_triangle(a: Vector2, b: Vector2, c: Vector2) -> float:
    return abs((a.x * (b.y - c.y) + b.x * (c.y - a.y) + c.x * (a.y - b.y)) * 0.5)

func main():
    var points: Array[Vector2] = [Vector2(4.0, 10.0), Vector2(3.0, 7.0), Vector2(8.0, 0.0)]

        calculate_area_of_triangle(points[0], points[1], points[2])

Is there a problem rewriting it like this, using two vectors from a common point?

func calculate_area_of_triangle(a: Vector2, b: Vector2) -> float:
    return abs(a.x*b.y - b.x*a.y)*0.5

func main():
    var points: Array[Vector2] = [Vector2(4.0, 10.0), Vector2(3.0, 7.0), Vector2(8.0, 0.0)]

        calculate_area_of_triangle(points[0]-points[2], points[1]-points[2])

From my tests I haven’t found an issue, but I worry there is something I’m not thinking about.

(I’m using this for calculating an area of polygon. This is for a calculating the area of non-hollow polygon. I take the vertices and subtract the center from them.)

1 Answer 1

1

There are no problems. You just calculate area of the same triangle being translated to put one vertex into coordinate origin. Result is correct

enter image description here

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.