代码之家  ›  专栏  ›  技术社区  ›  Fahad Nasrullah

如何在Android中找到形状的旋转点

  •  6
  • Fahad Nasrullah  · 技术社区  · 13 年前

    enter image description here

    我有一个形状e-g,Rectanle,我想把它旋转一个角度X,并想得到形状的更新旋转点。

    目前,对于对象的旋转,我使用canvas.rotate,但原始点保持不变;而不是旋转的那个。我正在使用此代码。

        canvas.save();
        canvas.rotate(angle, Pivate.x, Pivate.y);
        canvas.drawRect(left, top, right, bottom, redPaint);
        canvas.restore();
    

    任何帮助都将不胜感激。。。

    1 回复  |  直到 13 年前
        1
  •  5
  •   Ali Imran    13 年前

    您需要以下方法来获取更新点数组。。。

      float[] ptArr = new float[] { 20, 30, 60, 30, 60, 45, 20, 45};
    
    
      Matrix m = new Matrix();
      m.preRotate(angle, px, py); // where px and py is pivot point.
    
      m.mapPoints(ptArr);
      //at this point your array will be updated.
     canvas.drawPoints(ptArr, mPaint);