对于二三维同步中的三维视图肯定是需要通过二维元素来符号化成三维元素的,之前项目测试临时采用这个自代的圆管状:
esriSimple3DLineStyle AxisStyle = esriSimple3DLineStyle.esriS3DLSTube; 进行符号化,但是这个自带样式不能做更多的扩展,仍然需要对它进行手动graphic,今天花了半天时间看了下官方的例子,总算是捣鼓出了将指定坐标的两个点连成的线符号化成正方体状,中间也碰到一些问题。本以为arcengine提供了相当好的API,我只用传入两个点或是一根线,再给它一个Polygon,它就能帮我沿着这个线的方向画成正方体了,可是弄来弄去,不是位置不对,就是角度有问题,官方的例子过于简单,拿到我的应用中根本不能使用,于是分析了一下原因,采用以下三步:
第一步: 空间有根线,起点和终点肯定可以得到,我要沿这个线符号化成立方体,那么两点的长度肯定要用到。我们就在坐标原点沿Z坐标画一个立方体,高就是上面提到的线长。
第二步: 我们假定这根线的起点为(0,0,0),即我自定义的原点,通过IVector3D接口很容易得到这根线的偏移角度。这样就在原点把上面那个立方体给进行两次旋转得到正确的线段走向。
第三步: 将第二步的立方体平移到起点位置,完工。
public static IGeometry getCubeTubeByLinePoint(IPoint fPoint, IPoint tPoint, double width, double height) { //IPoint fPoint = GeometryUtilities.ConstructPoint3D(5, 6, 3); //IPoint tPoint = GeometryUtilities.ConstructPoint3D(15, 13, 13); //计算走向-->移动坐标原点 IVector3D tarPointV3D = GeometryUtilities.ConstructVector3D(tPoint.X - fPoint.X, tPoint.Y - fPoint.Y, tPoint.Z - fPoint.Z); //定义两次旋转的轴线 IVector3D axisOfRotationVector3D_Y = GeometryUtilities.ConstructVector3D(0, 10, 0); IVector3D axisOfRotationVector3D_Z = GeometryUtilities.ConstructVector3D(0, 0, 10); //定义走向线段 ILine extrusionLine = new LineClass(); extrusionLine.FromPoint = fPoint; extrusionLine.ToPoint = tPoint; double myToZ = extrusionLine.Length; //线段长度 //初始化截面形状 IPointCollection polygonPointCollection = new PolygonClass(); polygonPointCollection.AddPoint(GeometryUtilities.ConstructPoint2D(-(height / 2), (width / 2)),ref _missing, ref _missing); polygonPointCollection.AddPoint(GeometryUtilities.ConstructPoint2D((height / 2), (width / 2)), ref _missing, ref _missing); polygonPointCollection.AddPoint(GeometryUtilities.ConstructPoint2D((height / 2), -(width / 2)), ref _missing, ref _missing); polygonPointCollection.AddPoint(GeometryUtilities.ConstructPoint2D(-(height / 2), -(width / 2)), ref _missing, ref _missing); IPolygon polygon = polygonPointCollection as IPolygon; polygon.Close(); IGeometry polygonGeometry = polygonPointCollection as IGeometry; ITopologicalOperator topologicalOperator = polygonGeometry as ITopologicalOperator; topologicalOperator.Simplify(); //Perform Extrusion IConstructMultiPatch constructMultiPatch = new MultiPatchClass(); constructMultiPatch.ConstructExtrudeFromTo(0, myToZ, polygonGeometry); //旋转角度 ITransform3D transform3D = constructMultiPatch as ITransform3D; transform3D.RotateVector3D(axisOfRotationVector3D_Y, tarPointV3D.Inclination); transform3D.RotateVector3D(axisOfRotationVector3D_Z, GeometryUtilities.GetRadians(90) - tarPointV3D.Azimuth); //移动到起点 transform3D.Move3D(fPoint.X, fPoint.Y, fPoint.Z); return constructMultiPatch as IGeometry; }