autocad二次开发 2.旋转

autocad二次开发2

单个实体旋转

旋转对象使用变换矩阵的Rotation()函数,该函数要求输入用弧度表示的旋转角度、旋转轴和旋转基点。旋转轴用Vector3d对象表示,旋转基点用Point3d对象表示。旋转角度表示相对于当前位置将对象围绕基点旋转多远。

设立旋转轴

csharp 复制代码
//设置旋转轴为z轴
Matrix3d curUCSMatrix = doc.Editor.CurrentUserCoordinateSystem;
CoordinateSystem3d curUCS = curUCSMatrix.CoordinateSystem3d;
Vector3d axis = curUCS.Zaxis;

给定旋转角度

旋转角度为弧度制

csharp 复制代码
double angle = 90.0;
double radian = angle * Math.PI / 180.0;

设立基点

实体绕基点旋转

csharp 复制代码
Point3d basePoint = new Point3d(0, 0, 0);

旋转

csharp 复制代码
 entity.TransformBy(Matrix3d.Rotation(radian, axis, basePoint));

多对象集合旋转

创建集合

csharp 复制代码
 //建立曲线集合
 ObjectIdCollection enCollect = new ObjectIdCollection();
 enCollect.Add(entity.Id);
 enCollect.Add(entity.Id);
 enCollect.Add(entity.Id);
 ...

迭代旋转

csharp 复制代码
 for (int i = 0; i < enCollect.Count; i++)
 {
 	using (Arc arc = trans.GetObject(enCollect[i], OpenMode.ForWrite) as Arc)
	{
 		using (Arc arcr = arc.Clone() as Arc)
  		{
  			arcr.TransformBy(Matrix3d.Rotation(Math.PI, axis, basePoint));
            btr.AppendEntity(arcr);
            trans.AddNewlyCreatedDBObject(arcr, true);
         }
     }
 }
相关推荐
佚泽11 小时前
C# webApi学习笔记
笔记·学习·c#
魔法阵维护师12 小时前
从零开发游戏需要学习的c#模块,第二十四章(瓦片地图 —— 让世界有墙)
学习·游戏·c#
吴可可12312 小时前
C#中括号报错“应输入标识符”原因解析
c#
lingxiao1688813 小时前
智慧停车场(SmartParking)
c#·自动化·wpf
yngsqq15 小时前
加载dll失败
c#
吴可可12318 小时前
C#中is运算符的正确用法
c#
战族狼魂18 小时前
上位机软件开发完整学习路线与项目实战指南
单片机·c#·wpf
吴可可12318 小时前
Teigha自定义图元开发详解
c#