实体的镜像
本帖最后由 cdinten 于 2010-12-30 19:01 编辑貌似AutoCAD2006中实体没有Mirror方法,这让人很纠结,写了个程序演示实体的镜像,代码如下:
//Mirror Entity
public void MirrorEntity()
{
Database db = Application.DocumentManager.MdiActiveDocument.Database;
Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;
//对称平面
Plane mp = new Plane(new Point3d(1, 0, 0), new Point3d(0, 1, 0), new Point3d(0, 0, 1));
double x = mp.Normal.X;
double y = mp.Normal.Y;
double z = mp.Normal.Z;
double[] dm = new double;
dm = 1 - 2 * x * x;
dm = 1 - 2 * y * y;
dm = 1 - 2 * z * z;
dm=1;
dm = dm = -2*x * y;
dm = dm = -2*x * z;
dm = dm = -2*y * z;
Matrix3d Tm = new Matrix3d(dm);
using (Transaction trans = db.TransactionManager.StartTransaction())
{
BlockTable bt = (BlockTable)trans.GetObject(db.BlockTableId, OpenMode.ForRead);
BlockTableRecord btr = (BlockTableRecord)trans.GetObject(db.CurrentSpaceId, OpenMode.ForWrite);
Solid3d sld = new Solid3d();
sld.SetDatabaseDefaults();
sld.CreateBox(100, 150, 200);
sld.ColorIndex = 1;//red
btr.AppendEntity(sld);
trans.AddNewlyCreatedDBObject(sld, true);
Solid3d sldClone = sld.Clone() as Solid3d;
sldClone.ColorIndex = 3;//green
sldClone.TransformBy(Tm);
btr.AppendEntity(sldClone);
trans.AddNewlyCreatedDBObject(sldClone, true);
trans.Commit();
}
}
希望对大家能有所帮助。
详细的原理讲解可以看我的博客,链接为:http://379910987.blog.163.com/blog/static/33523797201011306586296/
还有简单的方法,:)
Matrix3d mat = Matrix3d.Mirroring(plane); 谢谢分享,学习了,
页:
[1]