Android Question How can I calculate the actual areas from a polygon?

Wolli013

Well-Known Member
Licensed User
Longtime User
If I have a rectangle, a square and a trapezoid in a polygon, how is it possible to calculate and output them individually from an open shape?
Attached code how I currently calculate the base area of a room.


B4X:
Sub CalculateFloorArea_orginal() As Double
    
    If walls.Size < 3 Then
        Log("Nicht genug Wände für eine Flächenberechnung")
        Return 0
    End If
    
    Dim area As Double = 0
    Dim n As Int = walls.Size

    For i = 0 To n - 1
        Dim wall1 As Map = walls.Get(i)
        Dim wall2 As Map = walls.Get((i + 1) Mod n)
        
        Dim x1 As Double = wall1.Get("x")
        Dim y1 As Double = wall1.Get("y")
        Dim x2 As Double = wall2.Get("x")
        Dim y2 As Double = wall2.Get("y")
        
        Dim partialArea As Double = x1 * y2 - x2 * y1
        area = area + partialArea
    Next

    area = 0.5 * Abs(area)
        Log("Berechnete Gesamtfläche: " & area)
            
    Return area

End Sub
 

MasterGy

Member
Licensed User
Hello!

How precise do you have to be?
If you really need to get into the math, then instead of the Gaussian area calculation, you can perhaps divide the plane into triangles. But that is another, more complicated solution.

If you want to avoid more complicated math, I would draw the polygon on a bitmap, paint its area, and count how many pixels are painted.
 
Upvote 0

Wolli013

Well-Known Member
Licensed User
Longtime User
nally, the calculations I am currently performing with the code are pretty accurate.
But I need the breakdown into the specific area types because I need to show how the final result was obtained. That's why I'm looking for such a decomposition in the individual areas to output them later.
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
Sorry, but I do not understand what exactly you are looking for.
If I have a rectangle, a square and a trapezoid in a polygon
What do you mean with this : rectangle in a polygon ?
Do you want to split a polygon into 'simple' surfaces or what else ?
I suppose that 'walls' is a List.
What does it contain ?
Then you use:
B4X:
Dim wall1 As Map = walls.Get(i)
Why a Map ? What is this for ?
 
Upvote 0

Wolli013

Well-Known Member
Licensed User
Longtime User
What do you mean with this : rectangle in a polygon ?
Do you want to split a polygon into 'simple' surfaces or what else ?

YES
 
Upvote 0

Wolli013

Well-Known Member
Licensed User
Longtime User
Here is an example:
There is now a rectangle and a square.
Now I would like both to be found and calculated and displayed individually according to the known formulas for area calculation, to prove how the dimensions come about.
 

Attachments

  • Aufmassflaeche.jpg
    87.6 KB · Views: 36
Upvote 0

klaus

Expert
Licensed User
Longtime User
Now I would like both to be found and calculated and displayed individually according to the known formulas for area calculation, to prove how the dimensions come about
Why ?
to prove how the dimensions come about.

Are you not sure of the calculation of the total area ?
 
Upvote 0

Wolli013

Well-Known Member
Licensed User
Longtime User
But I am sure and the surfaces also fit.
But for a measurement program, these areas must be shown individually.
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
But for a measurement program, these areas must be shown individually.
What kind of measurement program ?
How are the room surfaces defined ?
Couldn't these be directly defined with a kind of set of 'elementary' subsurfaces ?
And then you can do whatever you want.
 
Upvote 0

Wolli013

Well-Known Member
Licensed User
Longtime User
It is only a matter of dividing the base area into the specific shapes that are created by measuring the space in the round.
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
It is only a matter of dividing the base area into the specific shapes that are created by measuring the space in the round.
This is what i meant with 'a kind of set of 'elementary' subsurfaces', can't those be defined during the measurement.
One rectangle, then a second one and even others.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…