Esempio n. 1
0
        /// <summary>
        /// 起点坐标,角度,长度 绘制直线
        /// </summary>
        /// <param name="db">图形数据库</param>
        /// <param name="startPoint">起点</param>
        /// <param name="length">长苏</param>
        /// <param name="degree">角度</param>
        /// <returns></returns>
        public static ObjectId AddLineToModeSpace(this Database db, Point3d startPoint, Double length, Double degree)
        {
            // 利用长度和角度以及起点 计算终点坐标
            double  X        = startPoint.X + length * Math.Cos(BaseTools.AngleToDegree(degree));
            double  Y        = startPoint.Y + length * Math.Sin(BaseTools.AngleToDegree(degree));
            Point3d endPoint = new Point3d(X, Y, 0);

            return(db.AddEntityToModeSpace(new Line(startPoint, endPoint)));
        }
Esempio n. 2
0
        /// <summary>
        /// 绘制椭圆
        /// </summary>
        /// <param name="db">图形数据库</param>
        /// <param name="center">椭圆中心</param>
        /// <param name="majorRadius">长轴长度</param>
        /// <param name="shortRadius">短轴长度</param>
        /// <param name="degree">长轴与X夹角 角度值</param>
        /// <param name="startDegree">起始角度</param>
        /// <param name="endDegree">终止角度</param>
        /// <returns></returns>
        public static ObjectId AddEllipseToModeSpace(this Database db, Point3d center, double majorRadius, double shortRadius, double degree, double startDegree, double endDegree)
        {
            // 计算相关参数
            double   ratio     = shortRadius / majorRadius;
            Vector3d majorAxis = new Vector3d(majorRadius * Math.Cos(BaseTools.AngleToDegree(degree)), majorRadius * Math.Sin(BaseTools.AngleToDegree(degree)), 0);
            Ellipse  elli      = new Ellipse(center, Vector3d.ZAxis, majorAxis, ratio, BaseTools.DegreeToAngle(startDegree), BaseTools.DegreeToAngle(endDegree)); // VVector3d.ZAxis 等价于 new Vector3d(0,0,1) 平行于z轴法向量

            return(db.AddEntityToModeSpace(elli));
        }
Esempio n. 3
0
        /// <summary>
        /// 绘制正多边形
        /// </summary>
        /// <param name="db">图形数据库</param>
        /// <param name="center">多边形所在内接圆圆心</param>
        /// <param name="radius">所在圆半径</param>
        /// <param name="sideNum">边数</param>
        /// <param name="startDegree">起始角度</param>
        /// <returns></returns>
        public static ObjectId AddPolygonToModeSpace(this Database db, Point2d center, double radius, int sideNum, double startDegree)
        {
            // 声明一个多段线对象
            Polyline pLine = new Polyline();

            // 判断边数是否符合要求
            if (sideNum < 3)
            {
                return(ObjectId.Null);
            }
            Point2d[] point = new Point2d[sideNum]; // 有几条边就有几个点
            double    angle = BaseTools.DegreeToAngle(startDegree);

            // 计算每个顶点坐标
            for (int i = 0; i < sideNum; i++)
            {
                point[i] = new Point2d(center.X + radius * Math.Cos(angle), center.Y + radius * Math.Sin(angle));
                pLine.AddVertexAt(i, point[i], 0, 0, 0);
                angle += Math.PI * 2 / sideNum;
            }
            // 闭合多段线
            pLine.Closed = true;
            return(db.AddEntityToModeSpace(pLine));
        }
Esempio n. 4
0
        // 封装圆弧对象函数
        /// <summary>
        /// 绘制圆弧
        /// </summary>
        /// <param name="db">图形数据库</param>
        /// <param name="center">中心</param>
        /// <param name="radius">半径</param>
        /// <param name="startDegree">起始角度</param>
        /// <param name="endDegree">终止角度</param>
        /// <returns></returns>

        public static ObjectId AddArcToModeSpace(this Database db, Point3d center, double radius, double startDegree, double endDegree)
        {
            return(db.AddEntityToModeSpace(new Arc(center, radius, BaseTools.DegreeToAngle(startDegree), BaseTools.DegreeToAngle(endDegree))));
        }