明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 6666|回复: 7

UCS WCS DCS互转的方法

[复制链接]
发表于 2012-9-5 13:53 | 显示全部楼层 |阅读模式
本帖最后由 zhengjian211 于 2012-9-5 13:55 编辑

  1. public static Point3d Trans(this Point3d point, CoordinateSystemCode from, CoordinateSystemCode to)
  2.         {
  3.             return new Point3d(Trans(point.ToArray(), from, to));
  4.         }

  5.         public static Point3d Ucs2Wcs(this Point3d point)
  6.         {
  7.             return point.TransformBy(SystemManager.Editor.CurrentUserCoordinateSystem);
  8.         }

  9.         public static Vector3d Ucs2Wcs(this Vector3d vec)
  10.         {
  11.             return vec.TransformBy(SystemManager.Editor.CurrentUserCoordinateSystem);
  12.         }

  13.         public static Point2d Wcs2Dcs(this Point3d point, bool atPaperSpace)
  14.         {
  15.             return new Point2d(Trans(point.ToArray(), CoordinateSystemCode.Wcs, atPaperSpace ? CoordinateSystemCode.PDcs : CoordinateSystemCode.MDcs));
  16.         }

  17.         public static Vector2d Wcs2Dcs(this Vector3d vec, bool atPaperSpace)
  18.         {
  19.             return new Vector2d(Trans(vec.ToArray(), CoordinateSystemCode.Wcs, atPaperSpace ? CoordinateSystemCode.PDcs : CoordinateSystemCode.MDcs));
  20.         }

  21.         public static Point3d Wcs2Ucs(this Point3d point)
  22.         {
  23.             return point.TransformBy(SystemManager.Editor.CurrentUserCoordinateSystem.Inverse());
  24.         }

  25.         public static Vector3d Wcs2Ucs(this Vector3d vec)
  26.         {
  27.             return vec.TransformBy(SystemManager.Editor.CurrentUserCoordinateSystem.Inverse());
  28.         }


发表于 2019-9-7 17:08 | 显示全部楼层
1.WCS —— 世界坐标系即参照坐标系。其它所有的坐标系都是相对WCS定义的,WCS是永远不改变的。相对于WCS测量的值可以忽略其它坐标系统的变化。
2.UCS —— 用户坐标系统即工作中的坐标系。用户指定一个UCS以便绘图更容易。所有传到AutoCAD命令的点,包括那些从ObjectArx程序和外部功能返回的,都是当前UCS的点(除了在命令提示符后用户在前面加了个*的点)。通常,我们在自定义实体中使用的点都是以WCS来考虑的,当创建此实体时,如果需要用户输入一个点,由于此时CAD工作在UCS当中,得到的这个点需要转换成WCS,这样自定义实体才能正确地处理此点,否则将会产生错误。同理,如果自定义实体需要在UCS中显示出来时,也要需要将WCS转换成UCS。转换的函数是:acedTrans,关于此函数的使用,大家可以参考Arx的帮助文档“Coordinate System Transformations”这一节。

3.ECS —— 对象坐标系统-由多义线和细多义线对象的某些方法和属性指定的点的值由这种坐标系统表达,与对象有关。这些点通常根据对象的用途被转换成WCS、当前的UCS或当前的DCS。相反的,在WCS、UCS或DCS中的点依靠相同的属性写进数据库之前,必须被转换成ECS。当从ECS转换坐标或转换坐标到ECS时,你必须输入acedTrans函数中的最后一个参数ECS法线。

4.DCS —— 显示坐标系统即对象在显示前被转换的坐标系统。DCS的原点是被存在AutoCAD系统变量TARGET中的点,它的Z轴就是视图方向。换句话说,一个视口始终是它的DCS平面图。这些坐标可用于决定物体是从哪里显示给AutoCAD用户的。

5.PSDCS —— 图纸空间DCS-该坐标系统只能从当前活动的模型空间视口的DCS转入或转出。这本来是一个二维的转换,如果Disp变量为FALSE,X和Y坐标总是按比例来偏移的。Z坐标也是按比例的但是从不转换。因此,可以用Z坐标来找到两个坐标系统之间的比例因子。PSDCS只能被转换成当前的模型空间视口。如果转来的变量等于PSDCS,那么输出的变量必须等于DCS,反之亦然。

回复 支持 1 反对 0

使用道具 举报

发表于 2012-9-5 17:57 | 显示全部楼层
飞狐大版的原创,为何不写出处
发表于 2012-9-5 18:07 | 显示全部楼层
dcs是高版本的函数,低版本的只能使用ARX函数下面代码是根据Keen的C#代码改写的
  1. Imports System.Runtime.InteropServices
  2. Imports Autodesk.AutoCAD.Geometry
  3. Imports Autodesk.AutoCAD.DatabaseServices

  4. Module UCStoDcs
  5.     <DllImport("acad.exe", CallingConvention:=CallingConvention.Cdecl, EntryPoint:="acedTrans")> _
  6.     Public Function acedTrans(ByVal point() As Double, ByVal fromRb As IntPtr, ByVal torb As IntPtr, ByVal disp As Int16, ByVal result() As Double) As Int16
  7.     End Function
  8.     Public Function UCStoDisplay(ByVal Pointlist As List(Of Point3d)) As List(Of Point3d)
  9.         Dim rbFrom As ResultBuffer = New ResultBuffer(New TypedValue(5003, 0))
  10.         Dim rbTo As ResultBuffer = New ResultBuffer(New TypedValue(5003, 2))
  11.         Dim Mretlist As New List(Of Point3d)
  12.         Dim Mdcs = New Double() {0, 0, 0}
  13.         For Each pt As Point3d In Pointlist
  14.             acedTrans(pt.ToArray(), rbFrom.UnmanagedObject, rbTo.UnmanagedObject, 0, Mdcs)
  15.             Mretlist.Add(New Point3d(Mdcs))
  16.         Next
  17.         Return Mretlist
  18.     End Function
  19. End Module
查查arx函数,各种转就出来了,新版的net尤其是13对这方面做 了很多,也很全面了。
发表于 2018-3-19 09:50 | 显示全部楼层
请问DCS是什么坐标系?在网上没有找到相关资料。谢谢!
发表于 2020-2-25 08:49 来自手机 | 显示全部楼层
好东西,留存了
发表于 2020-3-14 19:45 | 显示全部楼层

非常感谢楼主!!!!
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2024-4-27 06:33 , Processed in 0.188957 second(s), 24 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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