C#中如何绘制一个四分之一的圆锥
思路:在C#中有自带的绘制圆锥的方法,
ConeElement coneElementLeft = new ConeElement(DgnModel dgnModel, Element templateElement, double topRadius, double bottomRadius, DPoint3d topCenter, DPoint3d bottomCenter, DMatrix3d rotation, bool isCapped);(这个创建方法对应的是MicroStation CE版本)
可这是绘制一个标准的圆锥,不能直接绘制出一个四分之一的圆锥,我们要通过剪切的思想,将原形体剪切好再放置相应的位置即可。
1.首先剪切好四分之一圆锥
//绘制圆锥
BIM.SmartSolidElement Cone_L = app.SmartSolid.CreateCone(null, 0, boxStraightWingWallData.C2 * mm/ Session.Instance.GetActiveDgnModel().GetModelInfo().UorPerMaster, boxStraightWingWallData.C2 * mm / Session.Instance.GetActiveDgnModel().GetModelInfo().UorPerMaster);
//绘制剪切圆锥的矩形体
BIM.SmartSolidElement Slab_L = app.SmartSolid.CreateSlab(null, 2*boxStraightWingWallData.C2 * mm / Session.Instance.GetActiveDgnModel().GetModelInfo().UorPerMaster, 2*boxStraightWingWallData.C2 * mm / Session.Instance.GetActiveDgnModel().GetModelInfo().UorPerMaster, boxStraightWingWallData.C2 * mm / Session.Instance.GetActiveDgnModel().GetModelInfo().UorPerMaster);
//将矩形体移到圆锥的一半位置
BIM.Point3d p1 = app.Point3dFromXYZ(boxStraightWingWallData.C2 * mm / Session.Instance.GetActiveDgnModel().GetModelInfo().UorPerMaster, 0, 0);
Slab_L.Move(p1);
//剪切一半的圆锥
BIM.SmartSolidElement Subtract_L = app.SmartSolid.SolidSubtract(Cone_L, Slab_L);
//将矩形体移到一半圆锥的一半位置
p1 = app.Point3dFromXYZ(-boxStraightWingWallData.C2 * mm / Session.Instance.GetActiveDgnModel().GetModelInfo().UorPerMaster, boxStraightWingWallData.C2 * mm / Session.Instance.GetActiveDgnModel().GetModelInfo().UorPerMaster, 0);
Slab_L.Move(p1);
//剪切一半的圆锥一半,Subtract_L即是四分之一圆锥
Subtract_L = app.SmartSolid.SolidSubtract(Subtract_L, Slab_L);
注:这里绘制出的剪切体是以原点为坐标,在移动矩形体剪切的时候默认为其几何中心点作为移动点的初始点,绘制方法对应的是MicroStation V8i版本。
2.其次通过旋转变换放置相应位置
//绕Z轴旋转法向量与Y轴的正方向的夹角
BIM.Matrix3d ma_L = app.Matrix3dFromVectorAndRotationAngle(app.Point3dFromXYZ(0, 0, 1), angle.Radians);
BIM.Transform3d ta_L = app.Transform3dFromMatrix3d(ma_L);
Subtract_L.Transform(ta_L);
//剪切体放置的位置点
BIM.Point3d P1 = ceDpoint_v8Point(leftCircleCenterPt);
Subtract_L.Move(P1);
P1 = app.Point3dFromXYZ(0, 0, boxStraightWingWallData.C2 / 2 * mm / Session.Instance.GetActiveDgnModel().GetModelInfo().UorPerMaster);
Subtract_L.Move(P1);
app.ActiveModelReference.AddElement(Subtract_L);
long id_L = Subtract_L.ID;
ElementId elemid_L = new ElementId(ref id_L);
Element temp_L = Session.Instance.GetActiveDgnModel().FindElementById(elemid_L);
注:ceDpoint_v8Point()这个方法是将CE的DPoint3d点转换为V8i的DPoint3d点,将绘制方法与放置位置点统一。
3.最后处理好的形体绘制在图纸上
temp_L.AddToModel();