Remove Extra Points from Curve Loop

Remove Extra Points from Curve Loop

zrodgersTSSSU
Advocate Advocate
566 Views
1 Reply
Message 1 of 2

Remove Extra Points from Curve Loop

zrodgersTSSSU
Advocate
Advocate

Hey Everyone, I am tryin to remove any points inside the main rectangle of points in my curve loop. I saw one post about this already but that solution did not work for me. Can someone guide me in the proper direction to do this efficiently?

 

my curve loop is the shown rectangle and the points i want to remove are highlighted with an x on them.

zrodgersTSSSU_0-1630428585311.png

THIS RETURNS 6 PTS NOT 4.

CurveLoop offsetCurveLoop = CurveLoop.CreateViaOffset(curveLoop, -1 * plywoodThickness, normal);

                                    //List<XYZ> args = HelperClass.CurveLoopCornerPoints(offsetCurveLoop);
                                    List<XYZ> args = new List<XYZ>(4);

                                    foreach (Curve curve in offsetCurveLoop)
                                    {
                                        XYZ pt = curve.GetEndPoint(0);
                                        args.Add(pt);
                                    }

 

 i did make a helper class to try and accomplish this but it only returns two points every time.

HELPER CLASS:

public static List<Autodesk.Revit.DB.XYZ> CurveLoopCornerPoints(this CurveLoop curveLoop)
        {
            List<Autodesk.Revit.DB.XYZ> points = new List<Autodesk.Revit.DB.XYZ>();
            List<Autodesk.Revit.DB.XYZ> pointsToRemove = new List<Autodesk.Revit.DB.XYZ>();
            foreach (Curve curve in curveLoop)
            {
                Autodesk.Revit.DB.XYZ pt = curve.GetEndPoint(0);
                points.Add(pt);
            }
            var result = points;
            for (int i = 0; i < points.Count; i++)
            {
                Autodesk.Revit.DB.XYZ firstPoint = points[i];

                for (int j = 0; j < points.Count; j++)
                {
                    if (firstPoint.ToString() != points[j].ToString())
                    {
                        Line line = Line.CreateBound(firstPoint, points[j]);
                        Autodesk.Revit.DB.XYZ startPoint = line.GetEndPoint(0);
                        Autodesk.Revit.DB.XYZ endPoint = line.GetEndPoint(1);

                        foreach (Autodesk.Revit.DB.XYZ xyz in points)
                        {
                            if (xyz.ToString() != startPoint.ToString() && xyz.ToString() != endPoint.ToString())
                            {
                                if (!pointsToRemove.Contains(xyz))
                                {
                                    pointsToRemove.Add(xyz);
                                }
                            }
                        }
                    }

                    if (pointsToRemove.Count > 0)
                    {
                        foreach (Autodesk.Revit.DB.XYZ point in pointsToRemove)
                        {
                            points.Remove(point);

                        }
                        result = points;
                    }

                }
            }
            return result;
        }

 

 

0 Likes
567 Views
1 Reply
Reply (1)
Message 2 of 2

jeremy_tammik
Alumni
Alumni

I would do the following:

 

  • Given the n points p[0], ... p[n-1]
  • Consider the vectors v = p[i] - p[i-1] and w = p[i+1] - p[i]
  • Check whether v and w are collinear
  • If so, eliminate p[i]
  • Add code to handle the border cases at index 0 and n-1, e.g., consider i = i % n

  

 

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open