<tfoot id='gyZct'></tfoot>

<small id='gyZct'></small><noframes id='gyZct'>

        <bdo id='gyZct'></bdo><ul id='gyZct'></ul>
    1. <i id='gyZct'><tr id='gyZct'><dt id='gyZct'><q id='gyZct'><span id='gyZct'><b id='gyZct'><form id='gyZct'><ins id='gyZct'></ins><ul id='gyZct'></ul><sub id='gyZct'></sub></form><legend id='gyZct'></legend><bdo id='gyZct'><pre id='gyZct'><center id='gyZct'></center></pre></bdo></b><th id='gyZct'></th></span></q></dt></tr></i><div id='gyZct'><tfoot id='gyZct'></tfoot><dl id='gyZct'><fieldset id='gyZct'></fieldset></dl></div>

    2. <legend id='gyZct'><style id='gyZct'><dir id='gyZct'><q id='gyZct'></q></dir></style></legend>
      1. 如何计算 java.awt.geom.Area 的面积?

        How to calculate the area of a java.awt.geom.Area?(如何计算 java.awt.geom.Area 的面积?)

        <legend id='xjaNw'><style id='xjaNw'><dir id='xjaNw'><q id='xjaNw'></q></dir></style></legend>
        <tfoot id='xjaNw'></tfoot>
        <i id='xjaNw'><tr id='xjaNw'><dt id='xjaNw'><q id='xjaNw'><span id='xjaNw'><b id='xjaNw'><form id='xjaNw'><ins id='xjaNw'></ins><ul id='xjaNw'></ul><sub id='xjaNw'></sub></form><legend id='xjaNw'></legend><bdo id='xjaNw'><pre id='xjaNw'><center id='xjaNw'></center></pre></bdo></b><th id='xjaNw'></th></span></q></dt></tr></i><div id='xjaNw'><tfoot id='xjaNw'></tfoot><dl id='xjaNw'><fieldset id='xjaNw'></fieldset></dl></div>
          <bdo id='xjaNw'></bdo><ul id='xjaNw'></ul>
            <tbody id='xjaNw'></tbody>

            <small id='xjaNw'></small><noframes id='xjaNw'>

                • 本文介绍了如何计算 java.awt.geom.Area 的面积?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在寻找一种方法来计算 java.awt.geom.Area 的任意实例的面积(以像素为单位).

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

                  背景:我的应用程序中有可能重叠的 Shape.我想知道一个 Shape 与另一个重叠多少.Shape 可能会倾斜、旋转等.如果我有一个函数 area(Shape)(或 Area),我可以使用两个 Shape 的交集如下:

                  The background: I have Shapes in my applications that may overlap. I want to know how much one Shape overlaps another. The Shapes may be skewed, rotated, etc. If I had a function area(Shape) (or Area), I could use the intersection of two Shapes like so:

                  double fractionObscured(Shape bottom, Shape top) {
                      Area intersection = new Area(bottom);
                      intersection.intersect(new Area(top));
                      return area(intersection) / area(bottom);
                  }
                  

                  推荐答案

                  一种方法是 fill() 每个都按比例缩放和 转换 Shape 使用合适的 AlphaComposite 和计算底层 中的重叠像素光栅.

                  One approach would be to fill() each scaled and transformed Shape with a different color using a suitable AlphaComposite and count the overlapping pixels in the underlying Raster.

                  附录1:使用这个计算器查看AlphaComposite.Xor表明任意两种不透明颜色的交集为零.

                  Addendum 1: Using this calculator to see the effect of AlphaComposite.Xor shows that the intersetion of any two opaque colors is zero.

                  附录2:计数像素可能存在性能问题;采样可能会有所帮助.如果每个 Shape 是相当凸的,可以从 intersect() 面积为 的面积之和Shapes' getBounds2D().例如,

                  Addendum 2: Counting pixels may have performance problems; sampling may help. If each Shape is reasonably convex, it may be possible to estimate the overlap from the ratio of the intersect() area to the sum of the areas of the Shapes' getBounds2D(). For example,

                  Shape s1, s2 ...
                  Rectangle2D r1 = s1.getBounds2D();
                  Rectangle2D r2 = s2.getBounds2D();
                  Rectangle2D r3 = new Rectangle2D.Double();
                  Rectangle2D.intersect(r1, r2, r3);
                  double overlap = area(r3) / (area(r1) + area(r2));
                  ...
                  private double area(Rectangle2D r) {
                      return r.getWidth() * r.getHeight();
                  }
                  

                  您可能需要凭经验验证结果.

                  You may need to validate the results empirically.

                  这篇关于如何计算 java.awt.geom.Area 的面积?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  How to send data to COM PORT using JAVA?(如何使用 JAVA 向 COM PORT 发送数据?)
                  How to make a report page direction to change to quot;rtlquot;?(如何使报表页面方向更改为“rtl?)
                  Use cyrillic .properties file in eclipse project(在 Eclipse 项目中使用西里尔文 .properties 文件)
                  Is there any way to detect an RTL language in Java?(有没有办法在 Java 中检测 RTL 语言?)
                  How to load resource bundle messages from DB in Java?(如何在 Java 中从 DB 加载资源包消息?)
                  How do I change the default locale settings in Java to make them consistent?(如何更改 Java 中的默认语言环境设置以使其保持一致?)

                    <legend id='opmBV'><style id='opmBV'><dir id='opmBV'><q id='opmBV'></q></dir></style></legend>
                      • <bdo id='opmBV'></bdo><ul id='opmBV'></ul>

                      • <small id='opmBV'></small><noframes id='opmBV'>

                          <tbody id='opmBV'></tbody>
                        <i id='opmBV'><tr id='opmBV'><dt id='opmBV'><q id='opmBV'><span id='opmBV'><b id='opmBV'><form id='opmBV'><ins id='opmBV'></ins><ul id='opmBV'></ul><sub id='opmBV'></sub></form><legend id='opmBV'></legend><bdo id='opmBV'><pre id='opmBV'><center id='opmBV'></center></pre></bdo></b><th id='opmBV'></th></span></q></dt></tr></i><div id='opmBV'><tfoot id='opmBV'></tfoot><dl id='opmBV'><fieldset id='opmBV'></fieldset></dl></div>

                            <tfoot id='opmBV'></tfoot>