Page 1 of 1

Modifying 2d curve by points

Posted: Mon Jul 13, 2020 3:44 am
by Matias Zambaldi
Hello all. I am trying to add 2D bspline modeling in my CAD-CAM application for Fenestration industry.

Usually CAD software allow to create and edit a nurbs by control points and by modifying points. Control points are easy as they are part of the curve definition, but I am having difficulty with meaning of the modifying points. In SketchUp, for example is it possible to move points to change the shape of the curve.
I want to be able to pick a point on the curve and move it to change the shape of the curve locally while keeping the rest of the curve unchanged. Is there an interface to do this? How could it be achieved?

Re: Modifying 2d curve by points

Posted: Tue Jul 21, 2020 5:56 am
by Sergei_O
Hi Matias
Have you tried IBSplineCurve2d_DG.aspx.ModifyPoint() ?

Re: Modifying 2d curve by points

Posted: Tue Jul 28, 2020 2:53 am
by Matias Zambaldi
Thank you, Sergei
I tried this. Something changes, but I am getting a shorter curve instead. What I am not clear about is how to get those indexPoleFrom, indexPoleTo indices.
I need some directions, please

Re: Modifying 2d curve by points

Posted: Wed Jul 29, 2020 3:02 am
by Prashant Kande
Hi Matias
The indices specify which part of the curve should be modified to pass through the new point.

If the curve was created by interpolation than you can get parameters for the interpolation points before and after the point to be moved. Parameter of a point is returned by ICurve_DG.GetNearestPoint().
Notice that the point does not have to lie exactly on the curve so the same method can be used for control points as well.

We have actually created a new sample to demo this. The main code:

Code: Select all

	void ModifySpline()
        {
	        ICurve_DG iCurve = m_iSplineCurve as ICurve_DG;
	        
	        Point_DG pt = new PointDg(m_pt.x[0], m_pt.x[1], m_pt.x[2]);
            	Point_DG ptNearest;
	        double u = iCurve.GetNearestPoint(pt, out ptNearest);

	        int i1 = FindPoleSegment(iCurve, u);					Debug.Assert(i1>=0);

	        PointDg ptNew = new PointDg(m_ptNew.x[0], m_ptNew.x[1], m_ptNew.x[2]);

            	int k0, k1;
            	m_iSplineCurve.ModifyPoint(u, ptNew, i1 - 1, i1, out k0, out k1);

	        // Set modified flag. Curve is too low-level attribute to know how to notify entity about the modification
	        IGeometry_DG iGeometry = m_iEntity.GetGeometry();
	        iGeometry.SetModified();
        }

        // Find two sequential poles adjacent to the picked point. Return index of the second
        int FindPoleSegment(ICurve_DG iCurve, double u)
        {
	        int n = m_iArrPnt.GetCount();

            	Point_DG ptNearest;
	        // Find the first definition point with parameter greater than u
	        // We also could have used projections of poles (nearest point) to the curve

	        for (int i=0; i<n; i++)
	        {
                	PointDg pt = m_iArrPnt.GetPoint(i);
                	double t = iCurve.GetNearestPoint(pt, out ptNearest);
		        if (t >= u)
			        return i;
	        }
	        return -1;
        }
See the attachment for full C# and VB projects. Please install today's or later update. We will make it official in v6.1 (coming out in few months)

2D case should be the same.

Re: Modifying 2d curve by points

Posted: Thu Jul 30, 2020 3:09 am
by Matias Zambaldi
That is nice, Prashant. Thank you.
Would this method work for interactive modification with a mouse?

Re: Modifying 2d curve by points

Posted: Fri Jul 31, 2020 12:08 am
by Prashant Kande
The sample is coded this way for simplicity. Yes you could code it in a mouse move handler. If it looks jerky, it might be better to do the modification on mouse up in the end and show a couple of straight lines during the stroke instead.

Re: Modifying 2d curve by points

Posted: Mon Aug 03, 2020 3:18 am
by Matias Zambaldi
Thank you for the help, Prashant
Matias