<bdo id='hcIYC'></bdo><ul id='hcIYC'></ul>

<tfoot id='hcIYC'></tfoot>
    1. <small id='hcIYC'></small><noframes id='hcIYC'>

    2. <legend id='hcIYC'><style id='hcIYC'><dir id='hcIYC'><q id='hcIYC'></q></dir></style></legend>

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

      1. 坐标算法 - 围绕中心旋转

        时间:2024-08-24

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

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

              <tbody id='dgKRP'></tbody>
            <legend id='dgKRP'><style id='dgKRP'><dir id='dgKRP'><q id='dgKRP'></q></dir></style></legend>

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

                  问题描述

                  通过查看这张图片,我想你会很好地理解我的问题:

                  By looking at this image I think you will understand my problem pretty well:

                  (图片已删除 - 网址不再有效,现在返回广告)

                  所以基本上我想要一个以对象为参数的函数,并根据我之前添加的对象数量为该对象提供正确的坐标.

                  So basically I want a function that takes an object as parameter and gives this object the correct coordinates based on how many objects I've added before.

                  假设我会将所有这些对象添加到一个数组中:

                  Let's say I would add all these objects to an array:

                  objectArray[]
                  

                  每次我添加一个新对象时:objectArray.add(object)

                  Each time I add a new object: objectArray.add(object)

                  object.xobject.y 坐标将基于某种算法设置:

                  The object.x and object.y coordinates will be set based on some algorithm:

                  object.x = ?
                  object.y = ?
                  

                  (我正在使用 Java)

                  (I'm working in Java)

                  感谢您的帮助.

                  推荐答案

                  这是不依赖循环的封闭式解决方案...我对 Java 不太熟悉,所以它在 C# 中,但它使用基本操作.

                  Here's the closed-form solution that doesn't rely on a loop... I'm not handy with Java, so it's in C#, but it uses basic operations.

                  static void SpiralCalc(int i) {
                      i -= 2;
                      // Origin coordinates
                      int x = 100, y = 100;
                      if (i >= 0) {
                          int v = Convert.ToInt32(Math.Truncate(Math.Sqrt(i + .25) - .5));
                          int spiralBaseIndex = v * (v + 1);
                          int flipFlop = ((v & 1) << 1) - 1;
                          int offset = flipFlop * ((v + 1) >> 1);
                          x += offset; y += offset;
                          int cornerIndex = spiralBaseIndex + (v + 1);
                          if (i < cornerIndex) {
                              x -= flipFlop * (i - spiralBaseIndex + 1);
                          } else {
                              x -= flipFlop * (v + 1);
                              y -= flipFlop * (i - cornerIndex + 1);
                          }
                      }
                      // x and y are now populated with coordinates
                      Console.WriteLine(i + 2 + "	" + x + "	" + y);
                  }
                  

                  这篇关于坐标算法 - 围绕中心旋转的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:如何根据二维数组上的特定位置获取网格单元的状态 下一篇:如何在 Vaadin 的视图中设置网格/表格中的单元格背景颜色?

                  相关文章

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

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

                      <legend id='t1yC2'><style id='t1yC2'><dir id='t1yC2'><q id='t1yC2'></q></dir></style></legend>