- Home /
calculate the area between these points pleasee
Hello, I am doing distance measurement application, when I click on the screen, I get the distance value between the points but I want to calculate the area between these points, how can I do the area calculation my code is here: Points.Add(andyObject);
if (Points.Count >= 2)
{
andyObject.GetComponent<LineRenderer>().positionCount = 2;
andyObject.GetComponent<LineRenderer>().SetPosition(0, andyObject.transform.position);
andyObject.GetComponent<LineRenderer>().SetPosition(1, Points[Points.Count - 2].transform.position);
var temp = Instantiate(Text, (andyObject.transform.position + Points[Points.Count - 2].transform.position) / 2, Quaternion.identity);
temp.transform.LookAt(andyObject.transform.position);
temp.transform.localEulerAngles = new Vector3(90, temp.transform.localEulerAngles.y + 90, 0);
temp.GetComponent<TextMesh>().text = (Vector3.Distance(andyObject.transform.position, Points[Points.Count - 2].transform.position) * 100).ToString("0.00");
}
Answer by Bunny83 · Jun 21, 2020 at 11:16 AM
I'm not sure what you're asking. There is no area between "points". You probably mean the area of the closed polygon that is made up of linesegments between the points? If that's the question, here's the answer as long as you talk about non overlapping polygons.
If you have a self-overlapping polygon there is no easy way to determine the whole area without splitting up the mesh. The method described in the answer I've linked would give the wrong intuitive answer but the right mathematical answer. This is best seen in my second gif animation. If you have a self-overlapping polygon you will have positive and negative area which of course cancel each other out. So the resulting area is essentially the green area minus the red area. Those can't be distinguished by this algorithm. If all that area should be counted as positive area, you would need to split the polygon in two at the intersection / overlapping point, process them seperately and add the results.
Your answer
