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);
         }
     }
 }
相关推荐
唐青枫9 小时前
别把日志、权限写进业务方法:C#.NET 动态代理从原理到实战
c#·.net
fujisheng66111 小时前
Unity UI 生命周期状态机:处理 Covered、异步竞态与事务回滚
c#·unity3d
leoZ23116 小时前
第 8 篇:与 AI 协作的工作流 + 完整案例
前端·人工智能·神经网络·自然语言处理·性能优化·c#·php
fujisheng66118 小时前
Unity 异步 UI 实战:取消令牌、版本校验与旧句柄隔离
c#·unity3d
额鹅恶饿呃18 小时前
随着CentOS官方停服的时间越来越久,大量仍在使用CentOS7的企业和运维从业者
java·python·算法·c#·ruby
乌药ice18 小时前
c#中一个多线程安全的HashSet
开发语言·c#
lfSeanDragon19 小时前
数据结构-前缀树(Trie)
开发语言·c#
张人玉19 小时前
基于 C# WinForms + .NET 8 + SQLite + TCP Socket 的多连接通讯调试工具——TCP通讯助手(TcpAssistant)
tcp/ip·sqlite·c#·.net
mldong1 天前
C# 开发者也有自己的轻量工作流引擎了:NuGet 装包,5 分钟跑通一条审批流
后端·c#·.net
samble1 天前
从零搭建工业控制系统(二十二):线程安全与并发控制
c#·wpf·并发·mvvm·线程安全·工业控制