我有一个矩形,周围有一些元素,用户可以用鼠标旋转它。这样的旋转可以与RotateTransform一起使用,但是旋转中心始终会存在一些偏移。 我这样计算中心:
this.rotationCenter = this.cornerA.CalculatePointOnLine(this.cornerC, 0.5);
CornerA和CornerC是矩形的角并建立对角线。 现在,我想相对于相应元素设置所有RotateTransforms的中心。
Logger.Logger.Write("coord.log", "center : " + this.rotationCenter.X + " ; " + this.rotationCenter.Y);
this.rotateSurroundingRectangle.CenterX = this.ParentLayer.TranslatePoint(this.rotationCenter, this.suroundingRectangle).X;
this.rotateSurroundingRectangle.CenterY = this.ParentLayer.TranslatePoint(this.rotationCenter, this.suroundingRectangle).Y;
Logger.Logger.Write("coord.log", "relative center : " + this.rotateSurroundingRectangle.CenterX + " ; " + this.rotateSurroundingRectangle.CenterY);
this.rotateResizeCorner1.CenterX = this.ParentLayer.TranslatePoint(this.rotationCenter, this.resizeCorner1).X;
this.rotateResizeCorner1.CenterY = this.ParentLayer.TranslatePoint(this.rotationCenter, this.resizeCorner1).Y;
this.rotateResizeCorner2.CenterX = this.ParentLayer.TranslatePoint(this.rotationCenter, this.resizeCorner2).X;
this.rotateResizeCorner2.CenterY = this.ParentLayer.TranslatePoint(this.rotationCenter, this.resizeCorner2).Y;
this.rotateResizeCorner3.CenterX = this.ParentLayer.TranslatePoint(this.rotationCenter, this.resizeCorner3).X;
this.rotateResizeCorner3.CenterY = this.ParentLayer.TranslatePoint(this.rotationCenter, this.resizeCorner3).Y;
this.rotateResizeCorner4.CenterX = this.ParentLayer.TranslatePoint(this.rotationCenter, this.resizeCorner4).X;
this.rotateResizeCorner4.CenterY = this.ParentLayer.TranslatePoint(this.rotationCenter, this.resizeCorner4).Y;
this.rotateRotationSign.CenterX = this.ParentLayer.TranslatePoint(this.rotationCenter, this.rotationSign).X;
this.rotateRotationSign.CenterY = this.ParentLayer.TranslatePoint(this.rotationCenter, this.rotationSign).Y;
根据角度,矩形周围所有元素的中心应更改,但矩形本身的中心应始终为32,32。 但是值会有所不同,X和Y的值都在29到35之间。 我已经检查了rotationCenter的计算,它是正确的。 为什么会出现这种偏差,我该如何解决? 谢谢...
答案 0 :(得分:0)
好的,因为似乎没有人有任何想法,所以我决定绕开这个问题,而不是实际解决它。所以现在我“手动”计算相对旋转中心。我不确定这是否会帮助任何人,但对我有用。
this.rotateSurroundingRectangle.CenterX = (this.surroundingRectangle.Width * 0.5);
this.rotateSurroundingRectangle.CenterY = (this.surroundingRectangle.Height * 0.5);
this.rotateResizeCorner1.CenterX = this.rotationCenter.X - Canvas.GetLeft(this.resizeCornerA);
this.rotateResizeCorner1.CenterY = this.rotationCenter.Y - Canvas.GetTop(this.resizeCornerA);
this.rotateResizeCorner2.CenterX = this.rotationCenter.X - Canvas.GetLeft(this.resizeCornerB);
this.rotateResizeCorner2.CenterY = this.rotationCenter.Y - Canvas.GetTop(this.resizeCornerB);
this.rotateResizeCorner3.CenterX = this.rotationCenter.X - Canvas.GetLeft(this.resizeCornerC);
this.rotateResizeCorner3.CenterY = this.rotationCenter.Y - Canvas.GetTop(this.resizeCornerC);
this.rotateResizeCorner4.CenterX = this.rotationCenter.X - Canvas.GetLeft(this.resizeCornerD);
this.rotateResizeCorner4.CenterY = this.rotationCenter.Y - Canvas.GetTop(this.resizeCornerD);
this.rotateRotationSign.CenterX = this.rotationCenter.X - Canvas.GetLeft(this.rotationSign);
this.rotateRotationSign.CenterY = this.rotationCenter.Y - Canvas.GetTop(this.rotationSign);