How to calculate the area of a java.awt.geom.Area?

后端 未结 4 448
清酒与你
清酒与你 2020-12-11 15:47

I am looking for a way to calculate the area, in pixels, of an arbitrary instance of java.awt.geom.Area.

The background: I have Shapes in m

4条回答
  •  心在旅途
    2020-12-11 16:44

    I would comment if I could. Suraj, your algorithm is correct, but the code should be

            int sum = 0;
            for (int i = 0; i < npoints ; i++)
            {
                sum = sum + Xs[i]*Ys[(i+1)%npoints] - Ys[i]*Xs[(i+1)%npoints];
            }
    
            return Math.abs(sum / 2);
    

    In your code last vertice is not taken into account. Just a small edit :)

提交回复
热议问题