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

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

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

        Java中的旋转矩形

        Rotate Rectangle in Java(Java中的旋转矩形)
        <tfoot id='J9TSO'></tfoot>
        1. <legend id='J9TSO'><style id='J9TSO'><dir id='J9TSO'><q id='J9TSO'></q></dir></style></legend>

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

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

                • 本文介绍了Java中的旋转矩形的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我需要创建围绕其中心旋转的矩形(因此它们不需要平行于坐标系的轴).所以基本上每个矩形都可以由 center-Xcenter-Ywidthheight 定义>角度.然后我想做的是计算某些点是否包含在这些矩形中(因此不涉及绘图).我想我不能使用 Rectangle2D 类,因为这些矩形总是平行于坐标系的 x 和 y 轴.是通过编写我自己的矩形类来获得此功能的唯一方法,还是我可以使用现有的任何东西(类似于 Rectangle2D)?

                  I need to create rectangles that are rotated around their center (so they don't need to be parallel to the axes of the coordinate system). So basicelly each rectangle can be defined by center-X, center-Y, width, height and angle. What I want to do then is to perform calculations on whether certain points are contained in these rectangles or not (so no drawing will be involved). I guess I cant use the Rectangle2D class because these rectangles will always be parallel to the x and y-axis of the coordinate system. Is the only way to get this functionality by writing my own rectangle class or is there anything existing (similar to Rectangle2D) I can use?

                  推荐答案

                  旋转所有要测试的点,像米海一样使用 Rectangle2D 的 contains(Point) 方法.

                  Rotate all the points you want to test and use contains(Point) method of the Rectangle2D as Mihai did.

                  但如果你真的想旋转矩形,你可以这样做(这是整数版本,但也许你也可以用 Rectangle2D 来做 :)).

                  But if you really want to rotate the rectangles you can do it like this (this is the integer version but probably you can do it with Rectangle2D aswell :)).

                  public class TestRotate {
                      public static void main(String... args) {
                  
                          Rectangle r = new Rectangle(50, 50, 100, 100);
                          Point check = new Point(100, 151); // clearly outside
                  
                          System.out.println("first: " + r.contains(check));
                  
                          AffineTransform at = AffineTransform.getRotateInstance(
                                  Math.PI/4, r.getCenterX(), r.getCenterY());
                  
                          Polygon p = new Polygon(); 
                  
                          PathIterator i = r.getPathIterator(at);
                          while (!i.isDone()) {
                              double[] xy = new double[2];
                              i.currentSegment(xy);
                              p.addPoint((int) xy[0], (int) xy[1]);
                              System.out.println(Arrays.toString(xy));
                  
                              i.next();
                          }
                  
                          // should now be inside :)
                          System.out.println("second: " + p.contains(check));
                      }
                  }
                  

                  这篇关于Java中的旋转矩形的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  Java Bytecode Manipulation Library Suggestions(Java 字节码操作库建议)
                  Java CLI UI-design: frameworks or libraries?(Java CLI UI 设计:框架还是库?)
                  About the use of Beans.xml configuration file in Spring Framework application(关于Spring Framework应用中Beans.xml配置文件的使用)
                  What is the difference between Spring, Struts, Hibernate, JavaServer Faces, Tapestry?(Spring、Struts、Hibernate、JavaServer Faces、Tapestry 有什么区别?)
                  Are there any android application framework like spring?(有没有像spring这样的android应用程序框架?)
                  Java Swing based game framework. Any advice?(基于 Java Swing 的游戏框架.有什么建议吗?)
                • <tfoot id='9E5D5'></tfoot>

                        • <bdo id='9E5D5'></bdo><ul id='9E5D5'></ul>

                            <small id='9E5D5'></small><noframes id='9E5D5'>

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

                              <tbody id='9E5D5'></tbody>
                            <legend id='9E5D5'><style id='9E5D5'><dir id='9E5D5'><q id='9E5D5'></q></dir></style></legend>