这是我的做法
- 做曲线
一个。创建曲线对象(尺寸、有理标志(是否有权重)、曲线度数+1、您有多少控制点)
ON_NurbsCurve thisCurve(3, false, order, controlPoints.size());
湾。向曲线添加控制点
for(int i = 0; i <controlPoints.size(); ++i)
{
ON_3dPoint cpPosition = controlPoints[i];
thisCurve.SetCV(i, cpPosition.x);
}
C。添加结
一、如果你有knot_count = cv_count + degree + 1
for (int i = 1; i < knotValues.size() - 1; ++i)
thisCurve.SetKnot(i - 1, knotValues[i]);
二、如果你有knot_count = cv_count + degree - 1
for (int i = 0; i < knotValues.size(); ++i)
thisCurve.SetKnot(i, knotValues[i]);
- 采样曲线
一个。检查曲线是否有效
if (thisCurve.IsValid())
{
湾。获取曲线的参数范围
double maxU = knotValues.back();
double minU = knotValues.front();
C。插
double quadrature = 10;
for (unsigned int i = 0; i < quadrature; ++i)
{
double t = ((maxU - minU) * (i) / (quadrature - 1)) + minU;
double pointsOut[3];
d。评估这需要(曲线的参数,多少导数,什么维度,存储值的双精度数组)
bool successful = thisCurve.Evaluate(t, 0, 3, pointsOut);
if (successful)
curvePoints.push_back(ON_3dPoint(pointsOut[0], pointsOut[1], pointsOut[2]));
else
std::cout << "evaluation not successful " << std::endl;
e. 清理
delete [] pointsOut;
}
thisCurve.Destroy();