Cannot get intersection points for spline (with 'Intersect.ExtendThis') to boundary curve

Cannot get intersection points for spline (with 'Intersect.ExtendThis') to boundary curve

trithuongle
Advocate Advocate
465 Views
4 Replies
Message 1 of 5

Cannot get intersection points for spline (with 'Intersect.ExtendThis') to boundary curve

trithuongle
Advocate
Advocate

Hello every body, I have a question.

I want to find the intersection points between spline and boundary like below .

trithuongle_0-1681309057321.png

In my code , i use 'Intersect.ExtendThis' , but it return no intersection points.

I tried to change it to 'Intersect.ExtendBoth' but it didn't work.

If i change curve to extend to another type of curve like arc or line or polyline . The function worked well.

I don't know why using with spline this problem is came out and how to fix this.

Thanks in advance !

//Check intersection with extending member curve :
                                memCurv.IntersectWith(boCurv, Intersect.ExtendThis , intPnts, IntPtr.Zero, IntPtr.Zero);

                                if (intPnts.Count == 0)
                                    //Skip to next entity :
                                    continue;
                                else
                                    //Call extend SubFunction :
                                    CmdTE_ExtendCurves(ed, tr, boCurv, memCurv, intPnts, stdPnt);

 

0 Likes
466 Views
4 Replies
Replies (4)
Message 2 of 5

leeminardi
Mentor
Mentor

Consider using the EndFitTangent function to define a line that can be used to define intersection with the boundary line.

lee.minardi
0 Likes
Message 3 of 5

trithuongle
Advocate
Advocate

@leeminardi  thank for your reply .

By the way after i got the intersection point. I tried to extend spline to this point but Autocad prompt me 

"eGeneralModelingFailure" .

if (memCurv.ObjectId.ObjectClass.
    IsDerivedFrom(RXClass.GetClass(typeof(Spline))))
{
    //Cast curve to spline :
    Spline splObj = (Spline)memCurv;

    //Update curve to open :
    splObj.UpgradeOpen();

    //Define point to extend :
    Point3d extPnt;

    if (splObj.StartPoint.DistanceTo(per.PickedPoint) <
        splObj.EndPoint.DistanceTo(per.PickedPoint))
        extPnt = splObj.StartPoint;
    else
        extPnt = splObj.EndPoint;

    Vector3d extVt = splObj.GetFirstDerivative(extPnt);

    using (Line tempLine = new Line())
    {
        //Create plane 2d to convert 3d geometry -> 2d geometry :
        var normal = ed.CurrentUserCoordinateSystem.CoordinateSystem3d.Zaxis;
        var plane = new Plane(Point3d.Origin, normal);

        //Find intersection point :
        tempLine.StartPoint = extPnt;
        tempLine.EndPoint = PolarXYonUCS(extPnt, extVt.AngleOnPlane(plane), extVt.Length);
        intPnts.Clear();
        tempLine.IntersectWith(boCurveSeg, Intersect.ExtendBoth, intPnts, IntPtr.Zero, IntPtr.Zero);
        if (intPnts.Count == 0 || intPnts.Count > 1)
        {
            return;
        }
        
        //Extend spline to intersection point :
        try
        {
            splObj.Extend(false, intPnts[0]);
        }
        catch (System.Exception ex)
        {
            ed.WriteMessage($"\nError : {ex.Message}");
            return;
        }

    }
}

Can you give me some ideas to fix this ?

Thanks in advance !

0 Likes
Message 4 of 5

leeminardi
Mentor
Mentor

@trithuongle I'm sorry to say that I have no experience with .Net.  Autodesk sent me your post and thought I could help.   Just to confirm,  intPnts is being calculated correctly and the issue is how to "stretch" the spline to this point? 

YOu might consider using something like  Spline.InsertControlPointAt Method but I don't see how you specify the inserted CV order with respect to the other CVs.  You want it to be the first or last CV.

lee.minardi
0 Likes
Message 5 of 5

trithuongle
Advocate
Advocate

@leeminardi  

Good afternoon , sorry for reply you late.

I think intPnts  is being calculated right ,but the problem is i cannot apply method curve.extend() for spline.

Thanks for your suggestion about ' Spline.InsertControlPointAt ' . I'm trying with this.

 

0 Likes