# [MSCE C#]获取控件中平面图案的顶点坐标

• 您指的是元素的包围盒还是下图中箭头所指的四个点的坐标，请注意元素旋转到不同方位时，这两组坐标是不一样的，如果是包围盒的话，有专门的函数DisplayableElement.CalcElementRange可以拿到。如果是箭头所指的点的坐标的话，需要将元素变换到局部坐标系下，然后获取其包围盒的四个点的左边，再变换回全局坐标系下。

• 郭老师，是指的箭头所指的顶点坐标，对于变换过程，我是这样算的，画出的矩形与这个图案重合，就算对了，但是结果不对额

``` cell.CalcElementRange(out DRange3d range);

DPoint3d lb = range.Low; //左下角
DPoint3d rt = range.High; //右上角
cell.GetTransformOrigin(out DPoint3d origin); //原点
cell.GetOrientation(out DMatrix3d orientation); //旋转矩阵

DTransform3d tran = DTransform3d.FromMatrixAndFixedPoint(orientation, origin);
DTransform3d tranMoveToZero = DTransform3d.FromTranslation(origin * -1);
tran = tranMoveToZero * tran;

tran.Multiply(out DPoint3d lb0, lb);
tran.Multiply(out DPoint3d rt0, rt);
lb0.Z = 0;
rt0.Z = 0;
DPoint3d[] pos = new DPoint3d[] {
new DPoint3d(lb0.X, rt0.Y, 0),
rt0,
new DPoint3d(rt0.X, lb0.Y, 0),
lb0,
};
ShapeElement eleRect = new ShapeElement(dgnModel, null, pos);

orientation.TryInvert(out DMatrix3d rot);
var tranToOrg = DTransform3d.FromMatrixAndTranslation(rot, origin);
eleRect.ApplyTransform(new TransformInfo(tranToOrg));

• 请看如下代码：

```CellHeaderElement cellEle = ele1 as CellHeaderElement;
cellEle.GetOrientation(out DMatrix3d orientation);
orientation.TryInvert(out DMatrix3d oriInvert);
cellEle.GetTransformOrigin(out DPoint3d origin);
DTransform3d dtran = DTransform3d.FromMatrixAndFixedPoint(oriInvert, origin);
cellEle.ApplyTransform(new TransformInfo(dtran));
cellEle.CalcElementRange(out DRange3d range);
DPoint3d[] ptArr = new DPoint3d[4] { range.Low,new DPoint3d(range.High.X,range.Low.Y,range.Low.Z), range.High,
new DPoint3d(range.Low.X,range.High.Y,range.Low.Z)};
dtran = DTransform3d.FromMatrixAndFixedPoint(orientation, origin);
dtran.MultiplyArrayInPlace(ptArr);
CurvePrimitive cvePri = CurvePrimitive.CreateLineString(ptArr);