Inkscape.org
Beginners' Questions How does the area calculation work?
  1. #1
    PhilippM PhilippM @PhilippM

    Hello to the forum.

    From a mathematical point of view, I am interested in how the area calculation for any shapes works in Inkscape. I managed to get the result via Extensions -> Visualize Path -> Measure Path... .

     

    Is it done with Gauss's Area calculation?
    https://en.wikipedia.org/wiki/Shoelace_formula
    Youtube: Gauss's magic shoelace area formula and its calculus companion

     

    Where can I find the source code of the area calculation?

     

    Thank you very much.

  2. #2
    inklinea inklinea @inklinea⛰️

    https://gitlab.com/inkscape/extensions/-/blob/master/measure.py

    """
    This extension module can measure arbitrary path and object length
    It adds text to the selected path containing the length in a given unit.
    Area and Center of Mass calculated using Green's Theorem:
    http://mathworld.wolfram.com/GreensTheorem.html
    """
    
  3. #3
    PhilippM PhilippM @PhilippM

    Hello inklinea,

    Thank you for your help and sorry for my late response.

    It is very interesting. I have to say, I never heard about Green's Theorem. How exactly is Green's Theorem implemented? Does in the Inkscape code in line 124 csparea return the area? But how is it calculated?

    If I understood it correctly, lineintegrals are computed to calculate the area. Which functions are used for P(x,y) and Q(x,y)?

     

    Thank you.

  4. #4
    inklinea inklinea @inklinea⛰️

    I'm not very good at maths as such. 

    If you look at the bottom of this page in the Inkscape extension api (inkex) there are some equations:

    https://inkscape.gitlab.io/extensions/documentation/source/inkex.bezier.html

    However I have no idea how they work, I just use them through the api :)

  5. #5
    PhilippM PhilippM @PhilippM

    Hello inklinea,

    It took me quite some time but now I understood it.

    The area of some curved shape is the polygon area of the points on the boundary plus all additional areas of the cubic Bezier curves.

     

     

    An additional area due to the cubic Bezier curve is calculated with Green's theorem:

     

    Here is the final formula:

     

     

     

     

     

     

     

    Thank you for the help.

    It was a really interesting topic for me.

     

Inkscape Inkscape.org Inkscape Forum Beginners' Questions How does the area calculation work?