如何实现2D对象绕自定义轴旋转?以红点为支点旋转透明矩形
2D对象绕自定义轴旋转实现方案
我正在尝试理解如何让2D对象绕自定义轴旋转,期望实现的效果是让透明矩形以红点作为支点进行旋转。

编辑补充:
以下是从选中答案中获取的可用代码,不过我需要将旋转操作放在位置设置之前才能生效,特此分享给后续读者:
Call Rotate_Object_About_Axis(objBookcaseB, objHinge, Range("rotation").Value) End Sub Private Sub Rotate_Object_About_Axis(RotObj As Shape, AxisObj As Shape, R_Deg As Double) Dim RotLoc1 As Coordinates Dim RotLoc2 As Coordinates Dim AxisLoc As Coordinates Dim R_Rad As Double Dim Pi As Double Pi = 3.14159 R_Rad = (R_Deg / 360 * (2 * Pi)) Debug.Print R_Rad Debug.Print R_Deg AxisLoc = ObjectLocation(AxisObj) RotLoc1 = ObjectLocation(RotObj) RotLoc2 = RotateCoordinates(AxisLoc.X, AxisLoc.Y, RotLoc1.X, RotLoc1.Y, R_Rad) With RotObj .Rotation = .Rotation + (R_Rad * 360 / (2 * Pi)) .Left = RotLoc2.X - (.Width / 2) '这一步必须放在旋转操作之后 .Top = RotLoc2.Y - (.Height / 2) '这一步必须放在旋转操作之后 End With End Sub Private Function ObjectLocation(Shp As Object) As Coordinates '获取对象的中心坐标 ObjectLocation.X = Shp.Left + (Shp.Width / 2) ObjectLocation.Y = Shp.Top + (Shp.Height / 2) End Function Private Function RotateCoordinates(Xa, Ya, X, Y, R) As Coordinates '根据旋转公式计算旋转后的坐标 'Xa, Ya:旋转支点坐标;X, Y:待旋转点原坐标;R:旋转弧度 RotateCoordinates.X = ((X - Xa) * Cos(R)) - ((Y - Ya) * Sin(R)) + Xa RotateCoordinates.Y = ((X - Xa) * Sin(R)) + ((Y - Ya) * Cos(R)) + Ya End Function
内容的提问来源于stack exchange,提问作者FMaz008
相关产品推荐
相关产品推荐

