乐筑天下

搜索
欢迎各位开发者和用户入驻本平台 尊重版权,从我做起,拒绝盗版,拒绝倒卖 签到、发布资源、邀请好友注册,可以获得银币 请注意保管好自己的密码,避免账户资金被盗
查看: 119|回复: 4

新手求教,请大神给注释一下下面的代码?

[复制链接]

2

主题

3

帖子

2

银币

初来乍到

Rank: 1

铜币
11
发表于 2016-6-20 11:31:00 | 显示全部楼层 |阅读模式
Public Function CreateUCS3Point(ByVal originWcs As Variant, ByVal xAxisPointWcs As Variant, ByVal yAxisPointWcs As Variant, _
    ucsName As String, ByRef objUCS As AcadUCS) As Boolean
    ' 如果pt1和pt2重合
    Dim math As New clsMath
    If math.PointIsEqual(originWcs, xAxisPointWcs) Then
        CreateUCS3Point = False
    End If
    Dim a1 As Double, b1 As Double, c1 As Double
    Dim a2 As Double, b2 As Double, c2 As Double
    Dim x As Double, y As Double, z As Double
    y = (yAxisPointWcs(1) + xAxisPointWcs(1)) / 2
    a1 = xAxisPointWcs(0) - originWcs(0) '
    b1 = xAxisPointWcs(2) - originWcs(2)
    c1 = (originWcs(1) - xAxisPointWcs(1)) * y
    a2 = ((xAxisPointWcs(1) - originWcs(1)) * (yAxisPointWcs(2) - originWcs(2))) - ((yAxisPointWcs(1) - originWcs(1)) * (xAxisPointWcs(2) - originWcs(2)))
    b2 = (a1 * (yAxisPointWcs(1) - originWcs(1))) - ((xAxisPointWcs(1) - originWcs(1)) * (yAxisPointWcs(0) - originWcs(0)))
    c2 = (a1 * (yAxisPointWcs(2) - originWcs(2)) - b1 * (yAxisPointWcs(0) - originWcs(0))) * y
    ' 如果三点共线或重合
    If (a1 * b2 - a2 * b1) = 0 Then
        CreateUCS3Point = False
    Else
    x = (c1 * b2 - c2 * b1) / (a1 * b2 - a2 * b1)
    z = (c2 * a1 - c1 * a2) / (a1 * b2 - a2 * b1)
    ' 将假定的偏移量加在坐标上
    Dim ptY(0 To 2) As Double
    SetPoint3d ptY, x + originWcs(0), y + originWcs(1), z + originWcs(2)
    Set objUCS = ThisDrawing.UserCoordinateSystems.Add(originWcs, xAxisPointWcs, ptY, ucsName)
    CreateUCS3Point = True
    End If
End Function
回复

使用道具 举报

2

主题

3

帖子

2

银币

初来乍到

Rank: 1

铜币
11
发表于 2016-6-20 11:32:00 | 显示全部楼层
实在是看不懂这段代码了,尤其是判断三点共线或重合这段。
请大侠指点,谢谢
回复

使用道具 举报

23

主题

561

帖子

13

银币

中流砥柱

Rank: 25

铜币
653
发表于 2016-6-20 18:47:00 | 显示全部楼层

三点共线,用向量叉积为0,这是高等数学的事儿
数学,对于编程来说很重要
回复

使用道具 举报

23

主题

561

帖子

13

银币

中流砥柱

Rank: 25

铜币
653
发表于 2016-6-20 18:48:00 | 显示全部楼层
去本论坛里的“几何算法”学习学习吧
回复

使用道具 举报

0

主题

4

帖子

1

银币

初来乍到

Rank: 1

铜币
4
发表于 2016-6-26 20:55:00 | 显示全部楼层
是的,是判断三点共线的,向量这个工具很有用
回复

使用道具 举报

发表回复

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

QQ|关于我们|小黑屋|乐筑天下 繁体中文

GMT+8, 2025-3-14 13:18 , Processed in 0.384891 second(s), 62 queries .

© 2020-2025 乐筑天下

联系客服 关注微信 帮助中心 下载APP 返回顶部 返回列表