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);
         }
     }
 }
相关推荐
rockey6272 小时前
基于AScript的python3脚本语言发布啦!
python·c#·.net·script·python3·eval·expression·function·动态脚本
工程师0072 小时前
C# 字符串不可变性 + 字符串驻留池原理
c#·字符串拘留池
唐青枫8 小时前
内存为什么越来越高?C#.NET GC 详解:分代回收、LOH、终结器与性能优化实战
c#·.net
xiaohe078 小时前
C#数据库操作系列---SqlSugar完结篇
网络·数据库·c#
yngsqq21 小时前
平面图环 内轮廓
c#
rockey6271 天前
AScript之eval函数详解
c#·.net·script·eval·expression·动态脚本
He少年1 天前
【AI 辅助案例分享】
人工智能·c#·编辑器·ai编程
工程师0071 天前
栈和堆的概念
c#·栈和堆
不会编程的懒洋洋1 天前
C# P/Invoke 基础
开发语言·c++·笔记·安全·机器学习·c#·p/invoke