PHP Classes
elePHPant
Icontem

Area of a polygon: How to calculate the area of a polygon?

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  All requests RSS feed  >  Area of a polygon  >  Request new recommendation  >  A request is featured when there is no good recommended package on the site when it is posted. Featured requests  >  No recommendations No recommendations  

Area of a polygon

A request is featured when there is no good recommended package on the site when it is posted. Edit

Picture of fikar by fikar - 5 months ago (2015-09-03)

How to calculate the area of a polygon?

This request is clear and relevant.
This request is not clear or is not relevant.

+3

I have tried the calculate distance class, but that is not good for this.

Now how about calculate polygon area in a map?

  • 2 Clarification requests
  • 2. Picture of Anthony Amolochitis by Anthony Amolochitis - 5 months ago (2015-09-04) Reply

    Do you need an exact area or an approximate area?

    Approximate area can use summations of length and height of leftmost to rightmost points from bottom up, top down, etc... The smaller the rectangular height, the closer to accurate you will be. That isn't the most efficient, but it is a start.

    If you need the exact area, you will need to use integration of a function. If you can define a function to draw the polygon, then it can be integrated. Maybe by breaking the polygon down to multiple triangles will help with this.

    Sounds like it's own little system. I will dwell on it some more. Great problem!

    • 1. Picture of Manuel Lemos by Manuel Lemos - 5 months ago (2015-09-04) Reply

      That is a tough problem to do in pure PHP if you do not know integral calculus. I do not know enough about it to figure an algorithm.

      Anyway, I think Google Maps API has function to calculate areas defined by polygons given their latitude and longitude coordinates.

      • 3. Picture of Olivier Plathey by Olivier Plathey - 5 months ago (2015-09-05) in reply to comment 1 by Manuel Lemos Comment

        There's no need to do any integral calculus.

        www.mathwords.com/a/area_convex_polygon.htm

      • 4. Picture of Samuel Adeshina by Samuel Adeshina - 5 months ago (2015-09-05) in reply to comment 3 by Olivier Plathey Comment

        Olivier Plathey, there's something called efficiency. Most of the Formulas on that page are meant for calculating the area of an irregular polygon by hand, they've not been properly optimized as an efficient algorithm should. These formulas would fail in situation where you need to calculate the area of a city from coordinates gotten from google maps or something similar

      • 5. Picture of Olivier Plathey by Olivier Plathey - 5 months ago (2015-09-05) in reply to comment 4 by Samuel Adeshina Comment

        Are you serious? Of course the formula is efficient. There are only some additions and multiplications. You can't do better.

        You will find a JS implementation here:

        www.mathopenref.com/coordpolygonarea2.html

        The function has only 6 lines!

      • 6. Picture of Manuel Lemos by Manuel Lemos - 5 months ago (2015-09-05) in reply to comment 3 by Olivier Plathey Comment

        Well the Earth is round, not flat. Those calculations seem to be meant to calculate areas of polygons defined on flat surfaces. That is why I suppose it may require integral calculus for polygons defined on round surfaces to be really accurate.

        Now, so polygons defined by vertices that are very close, the surface is almost flat. In that case those calculations for flat polygons would do.

      • 7. Picture of Samuel Adeshina by Samuel Adeshina - 5 months ago (2015-09-06) in reply to comment 6 by Manuel Lemos Comment

        Yeah, the best method for calculating the area of an hollow irregular polygonal shape or object is to integrate. Using Green's integral Theorem (Search for Green's Theorem on Wikipedia, external links are not allowed here), a formular can be derived for determining the area of an irregular polygon

    Ask clarification

    1 Recommendation

    Greens PHP Polygon Area: Calculate the area and perimeter of a polygon

    This recommendation solves the problem.
    This recommendation does not solve the problem.

    +2

    Picture of Samuel Adeshina by Samuel Adeshina package author package author Reputation 775 - 5 months ago (2015-09-05) Comment

    Check Out This Package. It accepts the coordinates of the vertices of the polygon you want to calculate and uses green's theorem to determine its area.

    It can also be used to determine the perimeter (distance) of a polygonal shape using the well known distance formula in physics.

    • 2 Comments
    • 1. Picture of Manuel Lemos by Manuel Lemos - 5 months ago (2015-09-07) Reply

      Yes, this can be used as an approximate solution for map areas defined by vertices not very far from each other, as when they are close you can consider the Earth is practically flat.

      Anyway for mapping calculations there still needs to be some kind of conversion between latitude and longitude and miles or kilometers, at least to a reference point.

    • 2. Picture of Samuel Adeshina by Samuel Adeshina package author package author - 5 months ago (2015-09-08) in reply to comment 1 by Manuel Lemos Reply

      Yes, thanks Mr. Manuel

      I just opened a new issue for that on the package's github repo. Will improve the algorithm as soon as possible


    Recommend package
    : 
    :