cad.net 转GeCurve求包围盒

public class TestCommand {
    [CommandMethod(nameof(CurveBoundDemo))]
    public void CurveBoundDemo() {
        using DBTrans tr = new();
        var pl = Env.Editor.SelectEntity<Polyline>("\n请选择多段线");
        if (pl is null) return;
    
        Curve3d curve3d = pl.GetGeCurve();
        CreateRect(curve3d.BoundBlock, 1);
        CreateRect(curve3d.OrthoBoundBlock, 2); // 这个才是对的

        Interval it = new Interval(1,1,0.1);
        double[] bs = it.GetBounds(); // 只有两个值
        for(int i = 0; i < bs.Length; i++) {
            Env.PrintLine(bs[i]);
        }
        var box = curve3d.GetBoundBlockOf();
        var box2 = curve3d.GetBoundBlockOf(it);

    }

    public void CreateRect(BoundBlock3d BoundBlock, int colorIndex) {
        var tr = DBTrans.Top;

        var left = BoundBlock.GetMinimumPoint().X;
        var bottom = BoundBlock.GetMinimumPoint().Y;
        var right = BoundBlock.GetMaximumPoint().X;
        var top = BoundBlock.GetMaximumPoint().Y;
        List<Point2d> pts = new();
        pts.Add(new Point2d(left, bottom));
        pts.Add(new Point2d(right, bottom));
        pts.Add(new Point2d(right, top));
        pts.Add(new Point2d(left, top));

        Polyline polyline = new Polyline();
        for(int i = 0; i < pts.Count; i++) {
            polyline.AddVertexAt(i, pts[i], 0, 0, 0);
        }
        polyline.ColorIndex = colorIndex;
        polyline.Closed = true;

        tr.CurrentSpace.AddEntity(polyline);
    }

}
posted @   惊惊  阅读(150)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· winform 绘制太阳,地球,月球 运作规律
· 超详细:普通电脑也行Windows部署deepseek R1训练数据并当服务器共享给他人
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· AI 智能体引爆开源社区「GitHub 热点速览」
· 写一个简单的SQL生成工具
点击右上角即可分享
微信分享提示