ObjectARX

Reply
Distinguished Contributor
421232206
Posts: 159
Registered: ‎10-21-2010
Message 1 of 5 (248 Views)
Accepted Solution

any way to draw closed spline only with PointsArray

248 Views, 4 Replies
04-25-2012 07:53 PM

HI, everyone,
    I have an array of 2d or 3d Points, and I want to draw a closed spline who passes the input points exactly.
    I found one of the AcdbSpline constructor,

AcDbSpline(
int degree,
Adesk::Boolean rational,
Adesk::Boolean closed,// this should be true
Adesk::Boolean periodic,
const AcGePoint3dArray& controlPoints,// I only have this.
const AcGeDoubleArray& knots,// I don't have this.
const AcGeDoubleArray& weights,// neither this
double controlPtTol = 0.0,
double knotTol = 0.0);

    Like the Spline commond in CAD, is there any way to draw a closed spline, I give the Points, and cad gives all the default params.

Technology change world! Coding change technology! We coders are coding!
Distinguished Mentor
owenwengerd
Posts: 593
Registered: ‎08-06-2002
Message 2 of 5 (242 Views)

Re: any way to draw closed spline only with PointsArray

04-25-2012 10:00 PM in reply to: 421232206

It sounds like you want to create a fit spline, which uses a different constructor.

--
Owen Wengerd
ManuSoft
Moderator
Alexander.Rivilis
Posts: 1,388
Registered: ‎04-09-2008
Message 3 of 5 (241 Views)

Re: any way to draw closed spline only with PointsArray

04-25-2012 10:10 PM in reply to: 421232206

cnngtdly wrote:

    I found one of the AcdbSpline constructor,
    Like the Spline commond in CAD, is there any way to draw a closed spline, I give the Points, and cad gives all the default params.


There are other AcDbSpline constructor's. For example:

AcDbSpline(const AcGePoint3dArray& points, int order = 4, double fitTolerance = 0.0); 

If you have to do spline closed:

static Acad::ErrorStatus MakeSplineClosed(AcDbSpline *pSpline)
{
  Acad::ErrorStatus es = Acad::eOk, esOpen = Acad::eOk;
  AcGePoint3dArray fitPoints;
  int degree;
  double fitTolerance;
  Adesk::Boolean tangentsExist;
  Adesk::Boolean tangentStartDef;
  Adesk::Boolean tangentEndDef;
  AcGeVector3d startTangent;
  AcGeVector3d endTangent;
  Adesk::Boolean rational;
  Adesk::Boolean closed;
  Adesk::Boolean periodic;
  AcGePoint3dArray controlPoints;
  AcGeDoubleArray knots;
  AcGeDoubleArray weights;
  double controlPtTol;
  double knotTol;
  AcGeNurbCurve3d *curv = NULL;
  if (pSpline->hasFitData()) {
    AcGeTol tol;
    if ((es = pSpline->getFitData(fitPoints,degree,fitTolerance,tangentsExist,startTangent,endTangent)) == Acad::eOk) {
      tangentStartDef = tangentsExist && (startTangent != AcGeVector3d::kIdentity);
      tangentEndDef   = tangentsExist && (endTangent   != AcGeVector3d::kIdentity);
      AcGeTol fitTol; fitTol.setEqualPoint(fitTolerance);
      curv = new AcGeNurbCurve3d(fitPoints, startTangent, endTangent, tangentStartDef, tangentEndDef, fitTol);
      curv->makeClosed();
      curv->getFitData(fitPoints, fitTol, tangentsExist, startTangent, endTangent);
      if ((esOpen = pSpline->upgradeOpen()) == Acad::eOk || (esOpen == Acad::eWasOpenForWrite)) {
        es = pSpline->setFitData(fitPoints, degree, fitTol. equalPoint(), startTangent, endTangent);
        if (esOpen != Acad::eWasOpenForWrite) pSpline->downgradeOpen();
      }
      delete curv;
    }
  } else {
    if ((es = pSpline->getNurbsData(degree, rational, closed, periodic, controlPoints, knots, weights, controlPtTol, knotTol)) == Acad::eOk) {
      if ((esOpen = pSpline->upgradeOpen()) == Acad::eOk || (esOpen == Acad::eWasOpenForWrite)) {
        es = pSpline->setNurbsData(degree, rational, Adesk::kTrue, periodic, controlPoints, knots, weights, controlPtTol, knotTol);
        if (esOpen != Acad::eWasOpenForWrite) pSpline->downgradeOpen();
      }
    }
  }
  return es;
}

 P.S.: This code was written 6 years ago and need to check it.


Пожалуйста не забывайте про Утвердить в качестве решения! Утвердить в качестве решения и Give Kudos!Баллы
Please remember to Accept Solution! Accept as Solution and Give Kudos!Kudos

Distinguished Contributor
421232206
Posts: 159
Registered: ‎10-21-2010
Message 4 of 5 (229 Views)

Re: any way to draw closed spline only with PointsArray

04-25-2012 11:56 PM in reply to: Alexander.Rivilis

thanks so much,Alexander. you always come out and give me greate help when needed. your code solved my problem perfectly.

Technology change world! Coding change technology! We coders are coding!
Active Contributor
varadan01
Posts: 47
Registered: ‎03-16-2012
Message 5 of 5 (173 Views)

Re: any way to draw closed spline only with PointsArray

07-06-2012 12:16 AM in reply to: Alexander.Rivilis

Dear Rivilis!

compare to autocad spline close with ur program code close command is not that much equal to autocad close command here the start and end tangents are same value that why the spline get wrong output.If u got correct code plz post ASAP. 

With Regards,
GVaradarajan

You are not logged in.

Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register

Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.

Need installation help?

Start with some of our most frequented solutions to get help installing your software.

Ask the Community