我使用此过程将 4 个边框的矩形旋转为 wpf 中的角:
'find the center
Dim center As New Point(((topRight.Margin.Left - topLeft.Margin.Left) / 2) + topLeft.Margin.Left,
((topLeft.Margin.Top - bottomLeft.Margin.Top) / 2) + bottomLeft.Margin.Top)
'shift the points to center and calculate the rotation
Dim tl As Point = getRotatedPoint(New Point(topLeft.Margin.Left - center.X,
topLeft.Margin.Top - center.Y), 1)
Dim tr As Point = getRotatedPoint(New Point(topRight.Margin.Left - center.X,
topRight.Margin.Top - center.Y), 1)
Dim bl As Point = getRotatedPoint(New Point(bottomLeft.Margin.Left - center.X,
bottomLeft.Margin.Top - center.Y), 1)
Dim br As Point = getRotatedPoint(New Point(bottomRight.Margin.Left - center.X,
bottomRight.Margin.Top - center.Y), 1)
'shift the points back from center and move
topLeft.Margin = New Thickness(tl.X + center.X, tl.Y + center.Y, 0, 0)
topRight.Margin = New Thickness(tr.X + center.X, tr.Y + center.Y, 0, 0)
bottomLeft.Margin = New Thickness(bl.X + center.X, bl.Y + center.Y, 0, 0)
bottomRight.Margin = New Thickness(br.X + center.X, +br.Y + center.Y, 0, 0)
getRotatedPoint 函数是:
'rotating the borders
Private Function getRotatedPoint(ByVal pnt As Point, ByVal degrees As Double)
Dim rAngle As Double = degrees * (Math.PI / 180)
Dim x As Double = pnt.X * Math.Cos(rAngle) - pnt.Y * Math.Sin(rAngle)
Dim y As Double = pnt.X * Math.Sin(rAngle) + pnt.Y * Math.Cos(rAngle)
Return New Point(x, y)
End Function
但我得到非常混乱的结果,我不知道,任何想法都会受到欢迎:)
edit1:我将 getRotatedPoint 函数更改为双精度,并添加了弧度到度数的转换。
edit2:修正弧度转换函数。
edit3:更正了中心坐标,但仍然会发生一些偏移。
edit4:这里是测试人员的示例项目:http: //dl.dropbox.com/u/33417300/testapp.zip