绕点旋转线 [英] Rotate line about a point

查看:53
本文介绍了绕点旋转线的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在VB Excel中绕其终点旋转一条水平线.我尝试了各种在Internet上找到的解决方案,但效果不佳.

I need to rotate an horizontal line about its end point in VB Excel. I tried various solution found on internet but they don't work well.

我给你一些有关我想做什么的图片:

I give you some images about what I want to do:

这是我的台词:
点A(72; 378)
B点(165; 378)

This is my line:
point A (72; 378)
point B (165; 378)

我想将点A绕点B旋转,旋转角度是可变的.例如,这是60度旋转

And I want to rotate the point A about the point B, the angle of rotation is variable. For example this is a 60 degrees rotation

截屏后在照片编辑器中添加了字母A和B

The letters A and B were added after the screenshot with a photo editor

推荐答案

尝试一下.

Sub test()
    Dim x As Single, y As Single
    Dim nx As Single, ny As Single, l As Single
    Dim i As Single, ra As Single
    Dim Ws As Worksheet
    Dim shp As Shape

    Set Ws = ActiveSheet
    For Each shp In Ws.Shapes
        If shp.Type = msoLine Then
            shp.Delete
        End If
    Next
    x = 165
    y = 378
    l = 165 - 72
    For i = 90 To 150
        ra = WorksheetFunction.Radians(i)
        nx = x - Sin(ra) * l
        ny = y + Cos(ra) * l
        Set shp = Ws.Shapes.AddLine(x, y, nx, ny)
        With shp
            .Line.EndArrowheadStyle = msoArrowheadTriangle
            .Line.ForeColor.RGB = RGB(255, 0, 0)
            .Line.Weight = 2
        End With
        DoEvents
        Application.Wait Now + (TimeSerial(0, 0, 1) / 2)
        shp.Delete

    Next i
    Set shp = Ws.Shapes.AddLine(x, y, nx, ny)
    With shp
        .Line.EndArrowheadStyle = msoArrowheadTriangle
        .Line.ForeColor.RGB = RGB(255, 0, 0)
        .Line.Weight = 2
    End With
End Sub

这篇关于绕点旋转线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆