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);
         }
     }
 }
相关推荐
波力海苔夹心脆6751 天前
C# WPF 资源字典详解:ResourceDictionary、MergedDictionaries 与自定义控件案例
开发语言·c#·wpf·入门教程·resource·资源字典
AI导出鸭PC端1 天前
Perplexity批量导出没有PDF模式?AI导出鸭插件补上最后一块拼图
人工智能·pdf·c#·ai导出鸭
Risehuxyc1 天前
C# 选用更流行的语言版本
c#
淡海水2 天前
09-04-内存-Unity原生对象生命周期
unity·c#·游戏引擎·gc
吴可可1232 天前
富怡CAD二次开发指南
c#
1-1=02 天前
C# IO和序列化
c#·.net·.netcore
寂寞的船2 天前
【Unity Bug挑战】第10期 SerializeReference 内存泄漏之谜
unity·c#·游戏引擎·bug
CSharp精选营2 天前
从控制台到「会动手」的 AI:用 Semantic Kernel 搭应用(小白教程)
c#·.net·ai agent·semantickernel·functioncalling
宝桥南山3 天前
.NET 11 - 尝试一下Blazor中的新特性SupplyParameterFromTempData
microsoft·微软·c#·asp.net·.net·.netcore
1-1=03 天前
C# 中 Lambda、Linq 与 Expression
c#·linq