该方法将点或位移从一个坐标系转换为另一个坐标系。TranslateCoordinates 称为 OriginalPoint 的点参数可以解释为 3D 点或 3D 位移向量。此参数由布尔参数 Disp 区分。如果 Disp 参数设置为 TRUE,则 OriginalPoint 参数被视为位移向量;否则,它被视为一个点。另外两个参数确定 OriginalPoint 来自哪个坐标系,以及 OriginalPoint 要转换为哪个坐标系。可以在“从”和“到”参数中指定以下 AutoCAD 坐标系:
将 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 |
|Archiver|CAD开发者社区 ( 苏ICP备2022047690号-1 苏公网安备32011402011833)
GMT+8, 2025-1-8 19:22
Powered by Discuz! X3.4
Copyright © 2001-2021, Tencent Cloud.