示例#1
0
        /// <summary>Создание дуг</summary>
        private void CreateArcs(XElement root, Transaction tr, BlockTableRecord btr)
        {
            foreach (XElement curveXelement in root.Elements("Arc"))
            {
                XElement startPointXElement = curveXelement.Element("StartPoint");
                Point3d  startPoint         = startPointXElement.GetAsPoint();
                XElement endPointXElement   = curveXelement.Element("EndPoint");
                Point3d  endPoint           = endPointXElement.GetAsPoint();
                XElement pointOnArcXElement = curveXelement.Element("PointOnArc");
                Point3d  pointOnArc         = pointOnArcXElement.GetAsPoint();
                // create a CircularArc3d
                CircularArc3d carc = new CircularArc3d(startPoint, pointOnArc, endPoint);

                // now convert the CircularArc3d to an Arc
                Point3d  cpt    = carc.Center;
                Vector3d normal = carc.Normal;
                Vector3d refVec = carc.ReferenceVector;
                Plane    plan   = new Plane(cpt, normal);
                double   ang    = refVec.AngleOnPlane(plan);
                using (Arc arc = new Arc(cpt, normal, carc.Radius, carc.StartAngle + ang, carc.EndAngle + ang))
                {
                    btr.AppendEntity(arc);
                    tr.AddNewlyCreatedDBObject(arc, true);
                }
                // dispose CircularArc3d
                carc.Dispose();
            }
        }
        public static Arc CreateArcFromRadius(this Editor acCurEd, Point3d startPoint, Point3d endPoint, double radius)
        {
            Arc arc     = null;
            var ucsMat  = acCurEd.CurrentUserCoordinateSystem;
            var vNormal = ucsMat.CoordinateSystem3d.Zaxis;
            var pStart  = startPoint.TransformBy(ucsMat); // Start point in WCS
            var pEnd    = endPoint.TransformBy(ucsMat);   // End point in WCS
            //  Finding center point of arc.
            var circ1 = new CircularArc3d(pStart, vNormal, radius);
            var circ2 = new CircularArc3d(pEnd, vNormal, radius);
            var pts   = circ1.IntersectWith(circ2);

            circ1.Dispose();
            circ2.Dispose();

            try
            {
                if (pts.Length < 1)
                {
                    return(null);
                }
            }
            catch (Exception)
            {
                return(null);
            }

            var      pCenter = pts[0];
            Vector3d v1 = pStart - pCenter, v2 = pEnd - pCenter;

            if (v1.CrossProduct(v2).DotProduct(vNormal) < 0)
            {
                pCenter = pts[1];
            }
            var cCirc    = new CircularArc3d(pCenter, vNormal, radius);
            var parStart = cCirc.GetParameterOf(pStart);
            var parEnd   = cCirc.GetParameterOf(pEnd);
            var parMid   = (parStart + parEnd) * 0.5;
            var pMid     = cCirc.EvaluatePoint(parMid);

            cCirc.Dispose();
            var cArc  = new CircularArc3d(pStart, pMid, pEnd);
            var angle =
                cArc.ReferenceVector.AngleOnPlane(new Plane(cArc.Center, cArc.Normal));

            arc = new Arc(cArc.Center, cArc.Normal, cArc.Radius, cArc.StartAngle + angle, cArc.EndAngle + angle);
            cArc.Dispose();
            return(arc);
        }