.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Getting Vertices Between two Points of a Polyline or Line in a Form of PointColl

4 REPLIES 4
Reply
Message 1 of 5
Anonymous
538 Views, 4 Replies

Getting Vertices Between two Points of a Polyline or Line in a Form of PointColl

Hi Guys

 

Could you Please help any one on the subjected request. As i Need to Get vertices Between Two user Selected Points in a polyline.

 

The Return Type I need it in the Form of Point3dCollection.

 

Thanks

 

Alex Andrews

4 REPLIES 4
Message 2 of 5
_gile
in reply to: Anonymous

Hi,

 

You can try the following code.

It assumes point1 and point2 are defined in WCS coordinates and the current view is Top.

For a solution working whatever the context, you can read the discussion I had with @ActivistInvestor about getting a point on curve in this post.

 

        private Point3dCollection GetPolylineVerticesBetweenPoints(Polyline pline, Point3d point1, Point3d point2)
        {
            double param1 = pline.GetParameterAtPoint(pline.GetClosestPointTo(point1, false));
            double param2 = pline.GetParameterAtPoint(pline.GetClosestPointTo(point2, false));
            double startParam = Math.Min(param1, param2);
            double endParam = Math.Max(param1, param2);
            int startIndex = (int)startParam;
            if (startIndex != startParam) startIndex++;
            int endIndex = (int)endParam;
            if (endIndex == endParam) endIndex++;
            var vertices = new Point3dCollection();
            for (int i = startIndex; i < endIndex; i++)
            {
                vertices.Add(pline.GetPoint3dAt(i));
            }
            return vertices;
        }


Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

Message 3 of 5
_gile
in reply to: _gile

Oopss...

There's a mistake in the upper code.

Try this one instead.

 

        private Point3dCollection GetPolylineVerticesBetweenPoints(Polyline pline, Point3d point1, Point3d point2)
        {
            double param1 = pline.GetParameterAtPoint(pline.GetClosestPointTo(point1, false));
            double param2 = pline.GetParameterAtPoint(pline.GetClosestPointTo(point2, false));
            double startParam = Math.Min(param1, param2);
            double endParam = Math.Max(param1, param2);
            int startIndex = (int)startParam;
            if (startIndex != startParam) startIndex++;
            int endIndex = (int)endParam + 1;
            var vertices = new Point3dCollection();
            for (int i = startIndex; i < endIndex; i++)
            {
                vertices.Add(pline.GetPoint3dAt(i));
            }
            return vertices;
        }


Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

Message 4 of 5
Anonymous
in reply to: _gile

Hi Gilles, Thanks for Helping me.

 

How ever I have few more issues, When handling with Different Geometries.

 

As "pline.GetPoint3dAt(i)" method is ssupportable for only Polylines; Incase of Lines, Arc, Spline, Its Can't be found... Could you Please Look into this?

 

 

Regards

 

Alex.

Message 5 of 5
ActivistInvestor
in reply to: Anonymous


@Anonymous wrote:

Hi Gilles, Thanks for Helping me.

 

How ever I have few more issues, When handling with Different Geometries.

 

As "pline.GetPoint3dAt(i)" method is ssupportable for only Polylines; Incase of Lines, Arc, Spline, Its Can't be found... Could you Please Look into this?

 

 

Regards

 

Alex.


You didn't ask for that.

 

Read the subject line of your post.  It says Vertices between two Points of a Polyline or Line.

 

Lines, arcs, splines, and other curves aside from polylines do not have vertices, so your question makes no sense from the outset.

 

 

 

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Forma Design Contest


AutoCAD Beta