Ejemplo n.º 1
0
        private static Curve CreateEdge(double rad, Edge edge, bool createArc)
        {
            Curve c = null;

            if (createArc)
            {
                // Calculate a mid-point for our arc

                var vec  = edge.End - edge.Start;
                var len  = vec.Length;
                var vmid = edge.Start + (vec * 0.5);
                vec = vec.RotateBy(Math.PI * 0.5, Vector3d.ZAxis);
                vec = -0.1 * vec;
                var mid = vmid + vec;

                // Create the initial arc between the center points of the
                // two nodes, as well as circles around the nodes

                var ca = new CircularArc3d(edge.Start, mid, edge.End);
                var c1 = new CircularArc3d(edge.Start, Vector3d.ZAxis, rad);
                var c2 = new CircularArc3d(edge.End, Vector3d.ZAxis, rad);

                // Intersect the arc with the two circles

                var pts1 = ca.IntersectWith(c1);
                var pts2 = ca.IntersectWith(c2);

                // Adjust the start and end of the arc, effectively trimming
                // it to the circles

                var newStart = edge.Start;
                var newEnd   = edge.End;
                if (pts1 != null && pts1.Length > 0)
                {
                    newStart = pts1[0];
                }
                if (pts2 != null && pts2.Length > 0)
                {
                    newEnd = pts2[0];
                }

                // Create our new, trimmed arc, and the database version of it

                var ca2 = new CircularArc3d(newStart, mid, newEnd);
                c = Arc.CreateFromGeCurve(ca2);
            }
            else
            {
                // Create the line - adjusted to go from the node circles)
                // and add it to the database

                var vec  = edge.End - edge.Start;
                var unit = vec / vec.Length;

                c = new Line(edge.Start + unit * rad, edge.End - unit * rad);
            }

            return(c);
        }
Ejemplo n.º 2
0
        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);
        }