good evening …
I have a heightmap and need to create a method that you select me anywhere in this heightmap to calculate the irregular selected area.
Thank you very much for your time…
stay tuned …
I have heigmap and I want to select any area of the field with the mouse to get the area in square meters
on a projected plan, on the surface and calculate area in meter squares…
Once is enough. If you want to add information then add information to the original. Asking again is not going to make it more likely to get answered. Just the opposite.
I’m not sure what your problem is, because the question is too open, so i will assume that you are in this situation
Where the green square is the area you want to measure and the red dots are known points. < EDIT > I just noticed you were talking about an irregular shape, the methods don’t change, though. But it’s trickier to find which pixels and triangles are inside that area. You could for example split it into known shapes. < / EDIT >
So, i know two ways that you can go through depending to your situation
Way1: The area is relative to the heightmap, thus in pixel coordinates
Knowing that an heightmap is a set of sampled heights of different points of a surface, and that every sample is represent by a pixel in the image which has a color that represent its height, you start from a pixel and then you take in account two adjacent pixels of the surrounding ones (note that when we talk about the position of a pixel, we are actually talking about the position of the center of the pixel )
For those 3 pixels you know the position and the color so you can easily translate them back to world coordinates, once you did that you can find the area of the triangle formed by those points, in world coordinates, that is now a part of the area you want to measure.
This is the basic logic, then you have to do this until you fill the desired area, there are probably several algorithms you could use for that.
Then you sum the areas you found and you have done.
Way2: The area is relative to the world
This is easier, but in order to have decent results you should have nearly one vertex per pixel… that is not the case usually, so maybe it’s better if you use way1 and translate the world pos in pixel coordinates before.
For this method, you work only with the mesh, you need to find which triangles have at least one point inside the interest area and calculate their area, sum, end.
Note that both methods (especially the second one) will give you really approximated results.
please start a code block with 3 backticks and end it with three backticks to make it better readable. many people dont and I dont understand why. would it make far better readable really. Its markdown.