ObjectARX
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

any way to draw closed spline only with PointsArray

4 REPLIES 4
SOLVED
Reply
Message 1 of 5
421232206
755 Views, 4 Replies

any way to draw closed spline only with PointsArray

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!
4 REPLIES 4
Message 2 of 5
owenwengerd
in reply to: 421232206

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

--
Owen Wengerd
ManuSoft
Message 3 of 5


@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.

Відповідь корисна? Клікніть на "ВПОДОБАЙКУ" цім повідомленням! | Do you find the posts helpful? "LIKE" these posts!
Находите сообщения полезными? Поставьте "НРАВИТСЯ" этим сообщениям!
На ваше запитання відповіли? Натисніть кнопку "ПРИЙНЯТИ РІШЕННЯ" | Have your question been answered successfully? Click "ACCEPT SOLUTION" button.
На ваш вопрос успешно ответили? Нажмите кнопку "УТВЕРДИТЬ РЕШЕНИЕ"


Alexander Rivilis / Александр Ривилис / Олександр Рівіліс
Programmer & Teacher & Helper / Программист - Учитель - Помощник / Програміст - вчитель - помічник
Facebook | Twitter | LinkedIn
Expert Elite Member

Message 4 of 5

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!
Message 5 of 5

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

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost