CAD开发者社区

 找回密码
 立即注册

QQ登录

只需一步,快速开始

ActiveX 开发指南

关于转换坐标 (VBA/ActiveX)

2023-1-4 21:15| 发布者: admin| 查看: 503| 评论: 0|来自: AutoCAD

摘要: “平移坐标”方法将点或位移从一个坐标系平移到另一个坐标系。

该方法将点或位移从一个坐标系转换为另一个坐标系。TranslateCoordinates

称为OriginalPoint 的点参数可以解释为 3D 点或 3D 置换矢量。这个论点的特点是布尔论证,Disp。如果Disp参数设置为 TRUE,则OriginalPoint参数将被视为位移矢量;否则,它被视为一个点。另外两个参数确定原始点来自哪个坐标系,以及原始要转换为哪个坐标系。可以在“从”和“至”参数中指定以下 AutoCAD 坐标系:

盐酸
世界坐标系:参考坐标系。所有其他坐标系都是相对于 WCS 定义的,WCS 永远不会更改。相对于 WCS 测量的值在更改其他坐标系时是稳定的。除非另有指定,否则传入和传出 ActiveX 方法和属性的所有点都在 WCS 中表示。
UCS
用户坐标系 (UCS):工作坐标系。用户指定 UCS 以使绘图任务更容易。传递给 AutoCAD 命令的所有点(包括从 AutoLISP 例程和外部函数返回的点)都是当前 UCS 中的点(除非用户在命令提示符下在它们前面加上 *)。如果希望应用程序将 WCS、OCS 或 DCS 中的坐标发送到 AutoCAD 命令,则必须首先通过调用该方法将它们转换为 UCS。TranslateCoordinates
法 团
对象坐标系:由 theandobject 的某些方法和属性指定的点值在此坐标系中相对于对象表示。这些点通常根据对象的预期用途转换为 WCS、当前 UCS 或当前 DCS。相反,WCS、UCS 或 DCS 中的点必须先转换为 OCS,然后才能通过相同的属性写入数据库。PolylineLightweightPolyline

当将坐标转换为 OCS 或从 OCS 转换坐标时,您必须在函数的最后一个参数中输入 OCS 的法线。TranslateCoordinates

DCS
显示坐标系:在显示对象之前对其进行变换的坐标系。DCS 的原点是存储在 AutoCAD 目标系统变量中的点,其Z轴是查看方向。换句话说,视口始终是其 DCS 的平面视图。这些坐标可用于确定向 AutoCAD 用户显示某些内容的位置。
私营部门发展中心
图纸空间 DCS:此坐标系只能变换到当前活动模型空间视口的 DCS 或从中转换。这本质上是一个 2D 转换,如果Disp参数为 FALSE,则始终缩放和偏移XY坐标。Z坐标已缩放,但从不平移。因此,它可用于查找两个坐标系之间的比例因子。PSDC 只能转换为当前模型空间视口。如果 from 参数等于 PSDCS,则 to 参数必须等于 DCS,反之亦然。

将 OCS 坐标转换为 WCS 坐标

本示例在模型空间中创建一条折线。然后,折线的第一个折点将显示在 OCS 和 WCS 坐标中。从 OCS 到 WCS 的转换需要将 OCS 的法线放在方法的最后一个参数中。TranslateCoordinates

Sub Ch8_TranslateCoordinates()
    ' Create a polyline in model space.
    Dim plineObj As AcadPolyline
    Dim points(0 To 14) As Double

    ' Define the 2D polyline points
    points(0) = 1: points(1) = 1: points(2) = 0
    points(3) = 1: points(4) = 2: points(5) = 0
    points(6) = 2: points(7) = 2: points(8) = 0
    points(9) = 3: points(10) = 2: points(11) = 0
    points(12) = 4: points(13) = 4: points(14) = 0

    ' Create a light weight Polyline object in model space
    Set plineObj = ThisDrawing.ModelSpace.AddPolyline(points)

    ' Find the X and Y coordinates of the
    ' first vertex of the polyline
    Dim firstVertex As Variant
    firstVertex = plineObj.Coordinate(0)

    ' Find the Z coordinate for the polyline
    ' using the elevation property
    firstVertex(2) = plineObj.Elevation

    ' Change the normal for the pline so that the
    ' difference between the coordinate systems
    ' is obvious.
    Dim plineNormal(0 To 2) As Double
    plineNormal(0) = 0#
    plineNormal(1) = 1#
    plineNormal(2) = 2#
    plineObj.Normal = plineNormal

    ' Translate the OCS coordinate into WCS
    Dim coordinateWCS As Variant
    coordinateWCS = ThisDrawing.Utility.TranslateCoordinates _
          (firstVertex, acOCS, acWorld, False, plineNormal)

    ' Display the coordinates of the point
    MsgBox "The first vertex has the following coordinates:" _
 & vbCrLf & "OCS: " & firstVertex(0) & ", " & _
 firstVertex(1) & ", " & firstVertex(2) & vbCrLf & _
 "WCS: " & coordinateWCS(0) & ", " & _
 coordinateWCS(1) & ", " & coordinateWCS(2)
End Sub

路过

雷人

握手

鲜花

鸡蛋

最新评论

QQ|Archiver|CAD开发者社区 ( 苏ICP备2022047690号-1 )

GMT+8, 2024-5-11 15:14

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

返回顶部