# How to calculate the areas of irregular shapes?

Hey, I am pretty new to Unity and game development. I am trying to make a game where a player will draw lines and create some random irregular shapes. How can I calculate these irregular areas when the player draws a line? I am not sure how to approach this problem. Currently, I am using line renderer to draw lines. So, I know where the lines begin and end. But, I don't know how to calculate the area automatically. Can someone give me some directions?

**Answer** by JVene
·
Nov 12, 2018 at 12:50 PM

There is a large body of math related to the subject, but the basic approach to what you've illustrated is to break the information into triangles (which are easy to calculate). You'll discover that the vertices that define such shapes can be traversed so as to identify multiple triangles that comprise the shape. This simplified approach relies on the notion that straight lines are used.

To be clear, examine the yellow region and notice it is a pair of triangles back to back. Given 3 sides, you can find the common method for area. The green region is comprised of 3 triangles, the white is 4.

You may also want to know that the GPU handles everything (in models) as triangles, and must store the vertices to make it trivial to "loop through" the triangles as connected areas for painting with textures. There are also algorithms you can find (Google, etc) which orient the vertices for such regions in order for triangle strips or fans, specifically for OpenGL or DirectX models (optimizing models for triangle strips). You might find them useful here.

In case it isn't obvious, once you have vertices ordered so you can "loop through" the triangles that comprise a region, you simply use the distance formulate to measure each side, from which you can obtain the area (use trig for area of non-right triangles to generalize).

Apparently, it is not a straightforward simple thing to do but I think I got the necessary keywords. Thanks :)

### Your answer

### Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.