如何在UWP中旋转线?

时间:2019-01-09 04:28:53

标签: c# uwp

目前,我通常需要根据角度围绕中点旋转一条线。我试过使用“旋转变换”,但它在某些角度下效果很好,但在其他角度下却没有给出确切的结果。请提出是否有解决方案。

cx= (line.X1+line.2)/2;
cy=(line.Y1+line.Y2)/2;   
RotateTransform transform = new RotateTransform();
transform.Angle = angle;
transform.CenterX = cx / zoomFactor;
transform.CenterY = cy / zoomFactor;
group.Children.Add(transform);
line.RenderTransform = group;                                                                                       

1 个答案:

答案 0 :(得分:0)

  var cx = new Point( (line.X2 - line.X1)/2,  (line.Y2 - line.Y1) / 2);
  var rotate = new RotateTransform
  {
    Angle = angle
  };

  var translate = new TranslateTransform
  {
    X = (line.X1 + cx.X),
    Y = (line.Y1 + cx.Y)
  };
  var group = new TransformGroup
  {
    Children =
    {
      (Transform) translate.Inverse,
      rotate,
      translate
    }
  };

  line.RenderTransform = group;