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);
         }
     }
 }
相关推荐
凌镜icecraft2 天前
我改文件扩展名的时候那个警告弹窗再也不会弹出来了
windows·c#·wpf·explorer
Jeff-Tsai2 天前
一个不用注册方法的 JSON-RPC 包,怎么决定哪些方法能被调用?
c#·.net·asp.net core·json-rpc
rockey6273 天前
AScript正式推出Template模板引擎
c#
沐言Agent3 天前
做工业上位机,这个 C# 开源框架把 PLC 通讯、流程控制和 MES 对接都备好了
c#·工业上位机
投研帮3 天前
C#文档管理系统开发实战:技术选型、全文检索与并发控制
c#·.net·文档管理系统
2395730494 天前
在 Avalonia 12 上用纯 .NET 重写 Monaco 编辑器:TKCode.Arc CodeEditor / DiffEditor / LSP 深度架构与实战
c#·.net·lsp·avalonia·monaco·codeeditor·tkcode.arc
新*4 天前
在 .NET 里嵌入 IronPython:内存只涨不降的真相与正确的封装姿势
c#·.net·内存优化·ironpython·dlr
2501_930707784 天前
使用C#从 PowerPoint 演示文稿中提取图片
开发语言·c#·powerpoint
zhanghaha13144 天前
C# 系列教程_15 类 Class 保姆级系统教程(面向新手,大量示例 + 底层机理)
java·开发语言·c#
Risehuxyc5 天前
HttpClient怎么传POST参数
c#