|
[code]1. AcdbPolyline的GetPointAt有两个:一个是获取二维点坐标(In OCS),一个是获取三维点坐标(In WCS)
Acad::ErrorStatus
getPointAt(
unsigned int index,
AcGePoint2d& pt) const;
This function sets pt to the 2D location of the vertexindex in thepolyline's own ojbect coordinate system (OCS).
Acad::ErrorStatus
getPointAt(
unsigned int unnamed,
AcGePoint3d& pt) const;
This function sets pt to the 3D location of the vertexindexin World Coordinates.
如果AcdbPolyLine不在x/y平面上的话,我们可以看出来,他们是不完全对应的:
例如下面的这个
Point: x-670.8292, y-18.2542
Point: x-670.8292, y-12.0000, z-18.2542
二维、三维之间如何转换呢?借助matrix可以完成转换:我们借助两个函数
AcDbEntity::getEcs Function
virtual void
getEcs(
AcGeMatrix3d& retVal) const;
retVal Output filled in with transformation matrix to go from OCS to WCS
AcDbPolyline::elevationFunction
double
elevation() const;
This returns the distance from the WCS origin to the plane of the polyline.
第一种方法: 通过getEcs获取其转换矩阵,通过elevation获取PLine线所在面 距 WCS原点的距离
(我们通过GetPointAt获取二维点时,其实他们本身是缺省带有z坐标elevation的---也就是PLine线所在面 距 WCS原点的距离)
AcGeMatrix3d matixToWCS;
pPlineTop->getEcs(matixTransToWCS);
double dElevetion = pPlineTop->elevation();
转换的时候:调用transformby,完成转换
注:dElevetion作为了z坐标
AcGePoint3d pt3dPoint = AcGePoint3d(pt2dTemp.x, pt2dTemp.y, dElevetion).transformBy(matixToWCS);
第二种方法: 把dElevetion也放到转换矩阵中来,直接转换
AcGeMatrix3d matixToWCS;
pPlineTop->getEcs(matixTransToWCS);
// 矩阵附加elevation的转换
matixTransToWCS *= AcGeMatrix3d::translation(AcGeVector3d::kZAxis * pPlineTop->elevation());
AcGePoint3d pt3dPoint = AcGePoint3d(pt2dTemp.x, pt2dTemp.y, dElevToWCS).transformBy(matixToWCS);
[/code] |
|