查看单个帖子
旧 2009-04-20, 09:14 PM   #1
yang686526
高级会员
 
注册日期: 06-11
帖子: 14579
精华: 1
现金: 224494 标准币
资产: 234494 标准币
yang686526 向着好的方向发展
默认 圆弧转多段线

圆弧转多段线
www.dimcax.com
圆弧转多段线
圆弧转多段线的问题,关键点在于多段线的“凸度”,很多网友对这“凸度”不是很清楚,所以我发这个帖子。 凸度是多段线顶点列表中选定顶点和下一顶点之间的圆弧所包含角度的 1/4 的正切值。负的凸度值表示圆弧从选定顶点到下一顶点为顺时针方向。凸度为0 表示直线段,凸度为1表示半圆。 “圆弧所包含角度”……就是“圆心角”,如果用圆弧的startangle属性和endangle属性来计算的,看似简单,却有很多麻烦……您可自己试试! 本程序中,圆心角的计算是通过弧长和半径来进行的,代码如下:
using system;
using autodesk.autocad.applicationservices;
using autodesk.autocad.databaseservices;
using autodesk.autocad.editorinput;
using autodesk.autocad.geometry;
using autodesk.autocad.runtime;
namespace cs_圆弧转多段线
{
public class class1
{
[commandmethod("test")]
public void test()
{
editor ed = application.documentmanager.mdiactivedocument.editor;
database db = hostapplicationservices.workingdatabase;
promptentityoptions opt = new promptentityoptions("\n请选择对象");
opt.setrejectmessage("您选择的不是圆弧,请重新选择!");
opt.addallowedclass(typeof(arc), true);
promptentityresult res = ed.getentity(opt);
if (res.status == promptstatus.ok)
{
polyline polylineent = new polyline();
using (transaction trans = db.transactionmanager.starttransaction())
{
arc arcent = (arc)trans.getobject(res.objectid, openmode.forwrite);
point3d p1 = arcent.startpoint;
point3d p2 = arcent.endpoint;
point2d[] pt = new point2d[2];
pt[0] = new point2d(p1.x, p1.y);
pt[1] = new point2d(p2.x, p2.y);
point2dcollection pts = new point2dcollection(pt);
double bulge = math.tan((arcent.length / arcent.radius) / 4);
for (int i = 0; i < pt.length; i++)
{
polylineent.addvertexat(i, pts[i], bulge, 0, 0);
}
blocktable bt = (blocktable)trans.getobject(db.blocktableid,
openmode.forread);
blocktablerecord btr = (blocktablerecord)trans.getobject
(bt[blocktablerecord.modelspace], openmode.forwrite);
btr.appendentity(polylineent);
trans.addnewlycreateddbobject(polylineent, true);
arcent.erase(true);
trans.commit();
}
}
}
}
}
复制代码
[
我以前的一编文章...
模具相关绿色软件
皆唯网
yang686526离线中   回复时引用此帖
GDT自动化论坛(仅游客可见)