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

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

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

      1. 围绕另一个点旋转一个点

        时间:2023-10-06
          <tbody id='uXq7Q'></tbody>
          <bdo id='uXq7Q'></bdo><ul id='uXq7Q'></ul>
          <tfoot id='uXq7Q'></tfoot>

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

          • <legend id='uXq7Q'><style id='uXq7Q'><dir id='uXq7Q'><q id='uXq7Q'></q></dir></style></legend>

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

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

                  问题描述

                  我的任务是绘制一个特定的图形.作为这项任务的一部分,我需要将一些点旋转 45 度.

                  I have a task to draw a specific graphic. As part of this task I need to rotate some dot's on 45 degrees.

                  我已经花了 2 天时间试图计算一个公式,但就是无法正确计算.我一直在到处搜索,包括这个特定的网站,我已经非常接近了,但我仍然不在那里.

                  I've spent already 2 days trying to calculate a formula, but just couldn't get it right. I've been searching all over the place including this particular website, I'm getting very close, but I'm still not there.

                  这里是:我需要画4个不同的点

                  Here it is: I need to draw 4 different points

                  我有一个特定的公式来计算那里的位置,这超出了问题的范围,但这是我得到的结果:

                  I have a specific formula to calculate there position, which is out of scope of the question, but here is what I'm getting as a result of it:

                  int radius = 576;
                  int diameter = radius * 2;
                  Point blueA = new Point(561, 273);
                  Point greenB = new Point(273, 561);
                  Point yellowC = new Point (849, 561);
                  Point redD = new Point (561, 849);
                  

                  现在我需要将这些点旋转 45 度.我使用下面的代码来实现它:

                  Now I need to rotate this dots on 45 degrees. I use the following code to achieve it:

                  double rotationAngle = 45;
                  double rotationRadians = rotationAngle * (Math.PI / 180);
                  int center = radius;    
                  result.X = (int)(Math.Cos(rotationRadians) * ((double)result.X - (double)center) - (double)Math.Sin(rotationRadians) * ((double)result.Y - center) + (double)center);
                  result.Y = (int)(Math.Sin(rotationRadians) * ((double)result.X - (double)center) + (double)Math.Cos(rotationRadians) * ((double)result.Y - center) + (double)center);
                  

                  但这就是我得到的:

                  任何帮助将不胜感激

                  推荐答案

                  问题是你设置的 int center = radius int radius = 576.这没有任何意义,因为您肯定正在围绕应该具有 x 和 y 位置的点旋转.

                  The problem is int center = radius which you are setting int radius = 576. This doesn't make sense as surely you are rotating about a point that should have an x and y location.

                  假设您围绕原点旋转,中心 xy 都应该是 0 而不是 576.

                  Given you are rotating around the origin the center x and y should both be 0 not 576.

                  所以,既然如此,试试这个.

                  So, given that, try this.

                  /// <summary>
                  /// Rotates one point around another
                  /// </summary>
                  /// <param name="pointToRotate">The point to rotate.</param>
                  /// <param name="centerPoint">The center point of rotation.</param>
                  /// <param name="angleInDegrees">The rotation angle in degrees.</param>
                  /// <returns>Rotated point</returns>
                  static Point RotatePoint(Point pointToRotate, Point centerPoint, double angleInDegrees)
                  {
                      double angleInRadians = angleInDegrees * (Math.PI / 180);
                      double cosTheta = Math.Cos(angleInRadians);
                      double sinTheta = Math.Sin(angleInRadians);
                      return new Point
                      {
                          X =
                              (int)
                              (cosTheta * (pointToRotate.X - centerPoint.X) -
                              sinTheta * (pointToRotate.Y - centerPoint.Y) + centerPoint.X),
                          Y =
                              (int)
                              (sinTheta * (pointToRotate.X - centerPoint.X) +
                              cosTheta * (pointToRotate.Y - centerPoint.Y) + centerPoint.Y)
                      };
                  }
                  

                  这样使用.

                  Point center = new Point(0, 0); 
                  Point newPoint = RotatePoint(blueA, center, 45);
                  

                  显然,如果中心点始终为 0,0,那么您可以相应地简化函数,或者通过默认参数或重载方法使中心点成为可选.您可能还希望将一些可重用的数学封装到其他静态方法中.

                  Obviously if the center point is always 0,0 then you can simplify the function accordingly, or else make the center point optional via a default parameter, or by overloading the method. You would also probably want to encapsulate some of the reusable math into other static methods too.

                  例如

                  /// <summary>
                  /// Converts an angle in decimal degress to radians.
                  /// </summary>
                  /// <param name="angleInDegrees">The angle in degrees to convert.</param>
                  /// <returns>Angle in radians</returns>
                  static double DegreesToRadians(double angleInDegrees)
                  {
                     return angleInDegrees * (Math.PI / 180);
                  }
                  
                  /// <summary>
                  /// Rotates a point around the origin
                  /// </summary>
                  /// <param name="pointToRotate">The point to rotate.</param>
                  /// <param name="angleInDegrees">The rotation angle in degrees.</param>
                  /// <returns>Rotated point</returns>
                  static Point RotatePoint(Point pointToRotate, double angleInDegrees)
                  {
                     return RotatePoint(pointToRotate, new Point(0, 0), angleInDegrees);
                  }
                  

                  这样使用.

                  Point newPoint = RotatePoint(blueA, 45);
                  

                  最后,如果您使用 GDI,您也可以简单地执行 RotateTransform.请参阅:http://msdn.microsoft.com/en-us/library/a0z3f662.aspx

                  Finally, if you are using the GDI you can also simply do a RotateTransform. See: http://msdn.microsoft.com/en-us/library/a0z3f662.aspx

                  Graphics g = this.CreateGraphics();
                  g.TranslateTransform(blueA);
                  g.RotateTransform(45);
                  

                  这篇关于围绕另一个点旋转一个点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:将二维数组放入列表框中 下一篇:旋转图像数学 (C#)

                  相关文章

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

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