You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何实现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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.03 00:55:35