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

      <tfoot id='BlF7w'></tfoot>

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

        Java中是否有像Rectangle类这样的circle类

        时间:2023-05-28

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

            <tbody id='mxRZX'></tbody>

              • <bdo id='mxRZX'></bdo><ul id='mxRZX'></ul>

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

                  本文介绍了Java中是否有像Rectangle类这样的circle类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  嘿,我正在编写一个快速程序,但遇到了一些需要使用圆圈进行碰撞检测的地方.但据我所知,只有 Rectangle 类具有 .intersects(Point p) 方法.有没有类似圆圈的东西可以用同样的方式使用?

                  解决方案

                  有一个类叫Ellipse2D 在您可以使用的 java.awt.geom 包中,因为它有一些看起来像您的方法重新寻找.宽度等于高度的椭圆是圆.

                  contains 的其中一个重载允许您测试圆点碰撞:

                  <块引用>

                  boolean contains(double x, double y)

                  测试指定的坐标是否在边界内Shape,正如内在定义所描述的那样.

                  另一个名为 intersects 的函数允许您测试圆与矩形的碰撞:

                  <块引用>

                  boolean intersects(double x, double y, double w, double h)

                  测试 Shape 的内部是否与指定矩形区域的内部相交.

                  注意 Ellipse2D 是一个抽象类;您可以使用其中一个嵌套子类 Ellipse2D.DoubleEllipse2D.Float,唯一的区别是用于存储维度的数据类型.

                  Hey I was writing a quick program and something came across where I need to use a circle for collision detection. But as far as I know, there is only the Rectangle class that has the .intersects(Point p) method. Is there anything like a circle that I could use the same way?

                  解决方案

                  There is a class called Ellipse2D in the java.awt.geom package that you can use, since it has some methods that appears to be what you're looking for. An ellipse with a width equal to its height is a circle.

                  One of the overloads for contains allows you to test for circle-point collisions:

                  boolean contains(double x, double y) 
                  

                  Tests if the specified coordinates are inside the boundary of the Shape, as described by the definition of insideness.

                  Another function called intersects allows you to test for circle-rectangle collisions:

                  boolean intersects(double x, double y, double w, double h)
                  

                  Tests if the interior of the Shape intersects the interior of a specified rectangular area.

                  Note that Ellipse2D is an abstract class; you would use one of its nested subclasses Ellipse2D.Double or Ellipse2D.Float, the only difference being the data type used to store the dimensions.

                  这篇关于Java中是否有像Rectangle类这样的circle类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:如何在Java中绘制一个实心圆? 下一篇:从圆心找到一点的角度

                  相关文章

                1. <small id='vZnRk'></small><noframes id='vZnRk'>

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

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