1 AutoCAD中的坐标系种类
-
WCS
World Coordinate System. The “reference” coordinate system. All other coordinate systems are defined relative to the WCS, which never changes. Values measured relative to the WCS are stable across changes to other coordinate systems.
世界坐标系(WCS),即“参考”坐标系。其它所有的坐标系都是相对WCS定义的,WCS是永远不改变的。无论坐标系统如何变化,相对于WCS测量的值均是不变的。 -
UCS
User Coordinate System. The “working” coordinate system. All points passed to AutoCAD commands, including those returned from AutoLISP routines and external functions, are points in the current UCS (unless the user precedes them with a * at the Command prompt). If you want your application to send coordinates in the WCS, ECS, or DCS to AutoCAD commands, you must first convert them to the UCS by calling acedTrans().
用户坐标系统(UCS),即“工作”坐标系。所有传到AutoCAD命令的点坐标——包括那些从ObjectArx程序和外部功能返回的——都是当前UCS坐标系统下的值(除了在命令提示符后用户在前面加了个*的点)。因此,当你想给AutoCAD命令发送坐标值时,请将WCS, ECS 或者 DCS 下的坐标值转换为UCS下坐标值。 -
ECS
Entity Coordinate System. Point values returned by acdbEntGet() are expressed in this coordinate system relative to the entity itself. Such points are useless until they are converted into the WCS, current UCS, or current DCS, according to the intended use of the entity. Conversely, points must be translated into an ECS before they are written to the database by means of acdbEntMod() or acdbEntMake().
实体坐标系。acdbEntGet()返回的点值在相对于实体本身的坐标系中表示。这些点坐标需要根据预期用途转换为WCS、UCS或DCS系统下的值。相反,在通过acdbEntMod()或acdbEntMake()将点写入数据库之前,必须将点坐标转换到ECS中。 -
DCS
Display Coordinate System. The coordinate system into which objects are transformed before they are displayed. The origin of the DCS is the point stored in the AutoCAD TARGET system variable, and its Z axis is the viewing direction. In other words, a viewport is always a plan view of its DCS. These coordinates can be used to determine where something appears to the AutoCAD user.
When the from and to integer codes are 2 and 3, in either order, 2 indicates the DCS for the current model space viewport, and 3 indicates the DCS for paper space (PSDCS). When the 2 code is used with an integer code other than 3 (or another means of specifying the coordinate system), it is assumed to indicate the DCS of the current space (paper space or model space), and the other argument is assumed to indicate a coordinate system in the current space.
显示坐标系统即对象在显示前被转换的坐标系统。DCS的原点是被存在AutoCAD系统变量TARGET中的点,它的Z轴就是视图方向。换句话说,一个视口始终是它的DCS平面图。这些坐标可用于决定物体是从哪里显示给AutoCAD用户的。
当acedTrans()中的from和to参数是2和3时,无论两者顺序如何,2表示当前模型空间的DCS坐标,3表示图纸空间的DCS。当参数为2和非3的参数被使用时,2被认为时当前空间的DCS坐标,另一个参数为该值在当前空间对应的坐标系。 -
PSDCS
Paper Space DCS. This coordinate system can be transformed only to or from the DCS of the currently active model space viewport. This is essentially a 2D transformation, where the X and Y coordinates are always scaled and are offset if the disp argument is 0. The Z coordinate is scaled but is never translated; it can be used to find the scale factor between the two coordinate systems. The PSDCS (integer code 2) can be transformed only into the current model space viewport: if the from argument equals 3, the to argument must equal 2, and vice versa.
图纸空间PDCS。此坐标系只能从当前活动模型空间视口的DCS转入或转出。这本质上是一个2D变换,如果disp参数为0,则X和Y坐标总是缩放偏移。Z坐标是缩放的,但从不平移;它可以用来找到两个坐标系之间的比例因子。PSDCS(整数代码2)只能转换到当前模型空间视口中:如果from参数等于3,则to参数必须等于2,反之亦然。
2 坐标转换
acedTrans()函数的作用是将一个点或位移从一个坐标系转换到另一个坐标系统。它采用一个点自变量pt,它可以被解释为三维点或三维位移向量。这是由一个称为disp的参数控制的,如果pt被视为位移向量,则disp必须为非零;否则,pt将被视为一个点。转换后的点或向量在通过引用调用的结果参数中返回,该参数与pt一样,类型为ads_point。
int acedTrans(const ads_point pt, const struct resbuf * from, const struct resbuf * to, int disp, ads_point result
);
指定两个坐标系(from和to)的参数都是结果缓冲区。from参数指定表示pt的坐标系,to参数指定结果的坐标系。from和to参数都可以通过以下任何方式指定坐标系:
-
整数值(restype == RTSHORT),指定了WCS,UCS或者DCS。 整数值包含几下几种:
- 0——World (WCS)
- 1——User (current UCS)
- 2——Display:DCS of current viewport when used with code 0 or 1.DCS of current model space viewport when used with code 3
- 3——Paper space DCS (PSDCS; used only with code 2)
-
实体名 (restype == RTENAME),该方式指定了实体的ECS。对平面实体来说,ECS可能和WCS不同。如果相同,在ECS与WCS的转换是相同的。
-
三维拉伸向量(restype==RT3DPOINT),这是指定实体ECS的另一种方法。拉伸矢量始终以世界坐标表示;(0,0,1)的拉伸向量指定WCS本身。
下面的例子将一个点坐标从WCS下转到UCS下。
ads_point pt, result;
struct resbuf fromrb, torb; pt[X] = 1.0;
pt[Y] = 2.0;
pt[Z] = 3.0; fromrb.restype = RTSHORT;
fromrb.resval.rint = 0; // WCS torb.restype = RTSHORT;
torb.resval.rint = 1; // UCS // disp == 0 indicates that pt is a point:
acedTrans(pt, &fromrb, &torb, FALSE, result);
3 关于DCS的特殊说明
3.1 DCS的详细说明
ObjectARX关于DCS的说明有以下几点。
- Eye Coordinate System
Every viewport has a vantage point, tilt, aim, and a field of view on the WCS. This is summed up in one transform, the viewport’s view transform. This transform converts world coordinate geometry into view coordinate geometry where the viewport’s view is down its Z-axis looking toward more negative values of Z. Eye coordinates do not contain the perspective transform. - Display Coordinate System
The Display Coordinate System (DCS) is the coordinate system into which objects are transformed before they are displayed. If not in perspective mode, the DCS is equivalent to the eye coordinate system. If perspective mode is active, the perspective transform must be performed on the eye coordinates to get display coordinates. The perspective transform gives the effect of geometry getting smaller the farther away it is from the camera.
根据以上叙述,DCS坐标系在非透视模式下和视觉坐标系是相同的,因此DCS可以理解为:原点为视图的目标点,Z轴为垂直当前平面的方向,X轴应为肉眼看向视图的右侧方向(请注意,不是UCS的X轴方向)。
3.2 视图的摆动角度是什么
视图有很多参数,可以通过CAD帮助文档的DView命令进行查看。
通过输入view命令,可以查看当前模型空间的视图参数。例如下图。
这里面只重点说明一个参数,摆动角度。这是其帮助文档的说明。
从说明可以看出,扭转角度是0°时就是视线水平向右的方向,而这个方向就是DCS的X轴方向。扭转角度旋转的原点是DCS的原点(而不是当前视图的中心点),另外,旋转的并不是DCS坐标系,而是视图的观察角度。举个例子:假如把观察者看作是照相机,照相机在给桌面上的底片拍照,扭转角度为30°时就是把底片逆时针转动30°。扭转角度实际上是视图绕着观察视线旋转的角度,而且,旋转的不是观察者,而是被观察对象。