public Point3d?Inters(Point3d p1, Point3d p2, Point3d p3, Point3d p4)
        {
            var r = Inters(p1.GetPoint2d(), p2.GetPoint2d(), p3.GetPoint2d(), p4.GetPoint2d());

            if (!r.HasValue)
            {
                return(null);
            }
            return(new Point3d(r.Value.X, r.Value.Y, 0.0));
        }
Example #2
0
        public void Avx()
        {
            int  ver          = AcAp.Version.Major;
            bool segHighlight = ver >= 18;
            bool loop         = true;

            PromptEntityOptions peo = new PromptEntityOptions(
                "\nSelet asegment where to add a vertex: ");

            peo.SetRejectMessage("\nPolyline only: ");
            peo.AllowNone = false;
            peo.AllowObjectOnLockedLayer = false;
            peo.AddAllowedClass(typeof(Polyline), false);
            while (loop)
            {
                PromptEntityResult per = ed.GetEntity(peo);
                if (per.Status != PromptStatus.OK)
                {
                    loop = false;
                    continue;
                }
                Matrix3d UCS   = ed.CurrentUserCoordinateSystem;
                ObjectId objId = per.ObjectId;
                try
                {
                    using (Transaction trans = db.TransactionManager.StartTransaction())
                    {
                        Polyline pline  = (Polyline)trans.GetObject(objId, OpenMode.ForRead, false);
                        Point3d  pickPt = pline.GetClosestPointTo(
                            per.PickedPoint.TransformBy(UCS),
                            ed.GetCurrentView().ViewDirection,
                            false);
                        double param = pline.GetParameterAtPoint(pickPt);
                        int    index = (int)param;

                        Matrix3d OCS     = Matrix3d.PlaneToWorld(pline.Normal);
                        Point3d  transPt = pickPt.TransformBy(OCS);

                        if (!OCS.CoordinateSystem3d.Zaxis.IsEqualTo(UCS.CoordinateSystem3d.Zaxis))
                        {
                            ed.CurrentUserCoordinateSystem = PlineUCS(pline, index);
                        }

                        var       aperture   = (Int16)AcAp.GetSystemVariable("APERTURE");
                        double    viewSize   = (double)AcAp.GetSystemVariable("VIEWSIZE");
                        Point2d   screenSize = (Point2d)AcAp.GetSystemVariable("SCREENSIZE");
                        double    tol        = 2 * aperture * viewSize / screenSize.Y;
                        Tolerance tolerance  = new Tolerance(tol, tol);

                        int endParam = pline.Closed ?
                                       pline.NumberOfVertices :
                                       pline.NumberOfVertices - 1;
                        Vector3d vec;
                        using (Polyline ghost = new Polyline())
                        {
                            ghost.ColorIndex = 1;

                            if (!pline.Closed && pickPt.IsEqualTo(pline.GetPoint3dAt(0), tolerance))
                            {
                                vec = pline.GetFirstDerivative(0);
                                double  bulge = pline.GetBulgeAt(0);
                                double  width = pline.GetStartWidthAt(0);
                                Point2d p0    = transPt.GetPoint2d();
                                Point2d p1    = pline.GetPoint2dAt(0);

                                ghost.AddVertexAt(0, p0, bulge, width, width);
                                ghost.AddVertexAt(1, p1, bulge, width, width);
                                ghost.Normal    = pline.Normal;
                                ghost.Elevation = pline.Elevation;
                                VertexJig jig = new VertexJig(ghost, pickPt, 0, vec, bulge,
                                                              width, width);
                                PromptResult res = ed.Drag(jig);
                                if (res.Status == PromptStatus.OK)
                                {
                                    pline.UpgradeOpen();
                                    pline.AddVertexAt(index, ghost.GetPoint2dAt(0),
                                                      ghost.GetBulgeAt(0), width, width);
                                }
                            }
                            else if (!pline.Closed && pickPt.IsEqualTo(pline.GetPoint3dAt(endParam),
                                                                       tolerance))
                            {
                                vec = pline.GetFirstDerivative(endParam);
                                double  bulge = pline.GetBulgeAt(index);
                                double  width = pline.GetEndWidthAt(endParam);
                                Point2d p0    = pline.GetPoint2dAt(endParam);
                                Point2d p1    = new Point2d(transPt.X, transPt.Y);

                                ghost.AddVertexAt(0, p0, bulge, width, width);
                                ghost.AddVertexAt(1, p1, bulge, width, width);
                                ghost.Normal    = pline.Normal;
                                ghost.Elevation = pline.Elevation;
                                VertexJig jig = new VertexJig(ghost, pickPt, 1, vec,
                                                              bulge, width, width);

                                PromptResult res = ed.Drag(jig);
                                if (res.Status == PromptStatus.OK)
                                {
                                    pline.UpgradeOpen();
                                    pline.AddVertexAt(endParam + 1, ghost.GetPoint2dAt(1),
                                                      ghost.GetBulgeAt(0), width, width);
                                    pline.SetBulgeAt(endParam, ghost.GetBulgeAt(0));
                                }
                            }
                            else
                            {
                                vec = pline.GetFirstDerivative(index);
                                double  bulge  = pline.GetBulgeAt(index);
                                double  sWidth = pline.GetStartWidthAt(index);
                                double  eWidth = pline.GetEndWidthAt(index);
                                Point2d p0     = pline.GetPoint2dAt(index);
                                Point2d p1     = transPt.GetPoint2d();
                                Point2d p2;
                                if (!pline.Closed)
                                {
                                    p2 = pline.GetPoint2dAt(index + 1);
                                }
                                else
                                {
                                    try { p2 = pline.GetPoint2dAt(index + 1); }
                                    catch { p2 = pline.GetPoint2dAt(0); }
                                }

                                FullSubentityPath subId = new FullSubentityPath(
                                    new ObjectId[] { pline.ObjectId },
                                    new SubentityId(SubentityType.Edge,
                                                    new IntPtr((long)index + 1)));
                                pline.Highlight(subId, false);
                                ghost.AddVertexAt(0, p0, bulge, sWidth, 0.0);
                                ghost.AddVertexAt(1, p1, bulge, 0, eWidth);
                                ghost.AddVertexAt(2, p2, 0.0, 0.0, 0.0);
                                ghost.Normal    = pline.Normal;
                                ghost.Elevation = pline.Elevation;
                                VertexJig jig = new VertexJig(ghost, pickPt, 1, vec,
                                                              bulge, sWidth, eWidth);
                                PromptResult res = ed.Drag(jig);
                                if (res.Status == PromptStatus.OK)
                                {
                                    pline.UpgradeOpen();
                                    pline.SetStartWidthAt(index, ghost.GetStartWidthAt(1));
                                    pline.AddVertexAt(
                                        index + 1,
                                        ghost.GetPoint2dAt(1),
                                        ghost.GetBulgeAt(1),
                                        ghost.GetStartWidthAt(1),
                                        eWidth);
                                    pline.SetBulgeAt(index, ghost.GetBulgeAt(0));
                                }
                                pline.Unhighlight(subId, false);
                            }
                        }
                        trans.Commit();
                    }
                }
                catch (Autodesk.AutoCAD.Runtime.Exception ex)
                {
                    ed.WriteMessage("\nError: " + ex.Message + ex.StackTrace);
                }
                finally
                {
                    ed.CurrentUserCoordinateSystem = UCS;
                }
            }
        }
 public static double GetAngleTo(this Point3d baze, Point3d pt)
 {
     return(baze.GetPoint2d().GetVectorTo(pt.GetPoint2d()).Angle);
 }