明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 658|回复: 4

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

[复制链接]
发表于 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

 楼主| 发表于 2016-6-20 11:32:06 | 显示全部楼层
实在是看不懂这段代码了,尤其是判断三点共线或重合这段。
请大侠指点,谢谢
发表于 2016-6-20 18:47:37 | 显示全部楼层
耕居琅琊郡 发表于 2016-6-20 11:32
实在是看不懂这段代码了,尤其是判断三点共线或重合这段。
请大侠指点,谢谢

三点共线,用向量叉积为0,这是高等数学的事儿
数学,对于编程来说很重要
发表于 2016-6-20 18:48:29 | 显示全部楼层
去本论坛里的“几何算法”学习学习吧
发表于 2016-6-26 20:55:09 | 显示全部楼层
是的,是判断三点共线的,向量这个工具很有用
您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|CAD论坛|CAD教程|CAD下载|联系我们|关于明经|明经通道 ( 粤ICP备05003914号 )  
©2000-2023 明经通道 版权所有 本站代码,在未取得本站及作者授权的情况下,不得用于商业用途

GMT+8, 2024-11-25 10:05 , Processed in 0.161195 second(s), 25 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表