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?
Modifying 2d curve by points
Re: Modifying 2d curve by points
Hi Matias
Have you tried IBSplineCurve2d_DG.aspx.ModifyPoint() ?
Have you tried IBSplineCurve2d_DG.aspx.ModifyPoint() ?
-
- Posts: 4
- Joined: Mon Jul 13, 2020 3:33 am
Re: Modifying 2d curve by points
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
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
-
- Posts: 121
- Joined: Mon Apr 04, 2016 4:55 am
Re: Modifying 2d curve by points
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:
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.
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;
}
2D case should be the same.
- Attachments
-
- SplineModsVB.zip
- (18.56 KiB) Downloaded 415 times
-
- SplineModsCS.zip
- (18.11 KiB) Downloaded 410 times
-
- Posts: 4
- Joined: Mon Jul 13, 2020 3:33 am
Re: Modifying 2d curve by points
That is nice, Prashant. Thank you.
Would this method work for interactive modification with a mouse?
Would this method work for interactive modification with a mouse?
-
- Posts: 121
- Joined: Mon Apr 04, 2016 4:55 am
Re: Modifying 2d curve by points
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.
-
- Posts: 4
- Joined: Mon Jul 13, 2020 3:33 am
Re: Modifying 2d curve by points
Thank you for the help, Prashant
Matias
Matias