|
[code]
using System;
using System.Text;
using Autodesk..ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Geometry;
using Autodesk.AutoCAD.Runtime;
namespace CsMgd1
{
public class Class1
{
Database db = HostApplicationServices.WorkingDatabase;
Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;
[CommandMethod("Test")]
public void Test()
{
ed.WriteMessage("\n绘制剖断线 By carrot1983");
PromptPointResult proPtRes1;
PromptPointOptions proPtOpts1 = new PromptPointOptions("\n指定第一点: ");
proPtRes1 = ed.GetPoint(proPtOpts1);
Point3d pt1 = proPtRes1.Value;
PromptPointResult proPtRes2;
PromptPointOptions proPtOpts2 = new PromptPointOptions("\n指定第二点: ");
proPtOpts2.UseDashedLine = true;
proPtOpts2.UseBasePoint = true;
proPtOpts2.BasePoint = pt1;
proPtRes2 = ed.GetPoint(proPtOpts2);
Point3d pt2 = proPtRes2.Value;
Point2dCollection pts = GetPoDuanPoints(pt1, pt2);
ObjectId pline = AddPline(pts, 0.0);
}
//取得两点间角度
public static double Get2PointsAngle(Point3d pt1, Point3d pt2)
{
Vector3d v1 = pt1.GetVectorTo(pt2);
return v1.GetAngleTo(Vector3d.XAxis);
}
//按方向和距离求取点
public static Point3d PolarPoint(Point3d basePt, double angle, double distance)
{
double[] pt = new double[3];
pt[0] = basePt[0] + distance * Math.Cos(angle);
pt[1] = basePt[1] + distance * Math.Sin(angle);
pt[2] = basePt[2];
Point3d point = new Point3d(pt[0], pt[1], pt[2]);
return point;
}
//计算剖断线的顶点表
public static Point2dCollection GetPoDuanPoints(Point3d pt1, Point3d pt2)
{
double ang = Get2PointsAngle(pt1, pt2);
Point3d leftPt = PolarPoint(pt1, ang+Math.PI, 56);
Point3d rightPt = PolarPoint(pt2, ang, 56);
Point3d middlePt = new Point3d((leftPt.X + rightPt.X) * 0.5, (leftPt.Y + rightPt.Y) * 0.5, (leftPt.Z + rightPt.Z) * 0.5);
Point3d leftPt1 = PolarPoint(middlePt, ang + Math.PI, 26);
Point3d leftPt2 = PolarPoint(PolarPoint(middlePt, ang + Math.PI, 12), ang + Math.PI * 0.5, 44);
Point3d rightPt1 = PolarPoint(middlePt, ang, 26);
Point3d rightPt2 = PolarPoint(PolarPoint(middlePt, ang, 12), ang + Math.PI * 1.5, 44);
Point2dCollection pts = new Point2dCollection();
pts.Add(new Point2d (leftPt.X,leftPt.Y));
pts.Add(new Point2d(leftPt1.X, leftPt1.Y));
pts.Add(new Point2d(leftPt2.X, leftPt2.Y));
pts.Add(new Point2d(rightPt2.X, rightPt2.Y));
pts.Add(new Point2d(rightPt1.X, rightPt1.Y));
pts.Add(new Point2d(rightPt.X, rightPt.Y));
return pts;
}
// 由二维点集合和线宽创建二维优化多段线的函数.
public static ObjectId AddPline(Point2dCollection pts, double width)
{
try
{
int n = pts.Count;
Polyline ent = new Polyline();
for (int i = 0; i 将Lisp的运行结果图片贴上让看看,不知道啥叫剖断线
|
|