Drawings SDK Developer Guide > Working with .dwg Files > Working with Entities > Working with Specific Entitites > Working with Splines > Working with Fit Data
Working with Fit Data

A spline can be specified by fit data that includes:

  • Set of fit points — Defines the three-dimensional points in WCS that specify the placement of the spline and adjust the shape of the curve. The number of fit points must be more than two. Fit points are indexed beginning at a zero.
  • Start tangent vector — Defines the curvature of a spline in the first point.
  • End tangent vector — Defines the curvature of a spline in the last point.
  • Tolerance — Defines how near and exact the spline curve passes through fit points.

The interface allows you to add a fit point to the fit data, delete a fit point from the fit data, modify coordinates of a fit point using its index, and change the tolerance of fit points. When you modify the coordinates of a fit point, the spline automatically recalculates its own knots and coordinates of control points. You can delete fit data from a spline entity and use only control points to adjusts its placement and shape.

Existing fit data

To find out whether a spline was constructed using fit points, use the hasFitData() method, which returns true if the spline has fit data or false if it does not have it. For example:


odPrintConsoleString(L"\nSpline %s fit data", ((pSpline->hasFitData()) ? L"has" : L"does not have"));

Number of fit points

To get the number of spline fit points, use the numFitPoints() method, which returns the number of fit points as an integer value. For example:


odPrintConsoleString(L"\nSpline has %d fit points", pSpline->numFitPoints());

Getting fit point data

To get data of each fit point, use the getFitPointAt() method, which requires two parameters: an integer value for specifying the index of the fit point and a reference to an OdGePoint3d object through which the point data will be returned. For example:


for (int i = 0; i < pSpline->numFitPoints(); i++)
{
  OdGePoint3d p;
  pSpline->getFitPointAt(i,p);
  odPrintConsoleString(L"\nFit point %d coordinates: %f %f %f", i, p.x, p.y, p.z);
}

Changing fit point data

To change an existing fit point, use the setFitPointAt() method, which requires two parameters: an integer value for specifying the index of the existing fit point and a reference to an OdGePoint3d object where the new fit point data is stored. For example:


OdGePoint3d p;
// Get the existing fit point
pSpline->getFitPointAt(3,p);
// Change point data
p.x += 3;
p.y += 3;
p.z += 3;
// Set new data to the spline
pSpline->setFitPointAt(3,p);

Adding new fit point

To add a new fit point into the spline, use the insertFitPointAt() method, which requires two parameters: an integer value to specify the index of a new point and a reference to an OdGePoint3d object as a new fit point.
For example:


pSpline->insertFitPointAt(3, OdGePoint3d(10.0,10.0, 0.0));

Note: If the point index is less than zero, a new point will be added to the beginning of the array of fit points; if the point index is bigger than or equal to the number of fit points, a new point will be added to the end of the array of fit points.

Removing an existing fit point

To remove an existing fit point, use the removeFitPointAt() method, which requires one integer parameter for the fit point index. For example:


pSpline->removeFitPointAt(1);

Fit tolerance

Fit tolerance defines how near and exact the curve must pass through fit points. If the fit tolerance is set to zero, the spline will pass through all of the fit points. Providing a value greater than zero allows the curve to pass through the fit points within the specified tolerance.

To get the tolerance of fit points, use the fitTolerance() method, which returns the point tolerance as a double value. For example:


odPrintConsoleString(L"\nFit tolerance of the spline is %f", pSpline->fitTolerance());

To set a new fit tolerance to the spline, use the setFitTol() method, which requires one double value to specify the new fit tolerance of the spline. For example:


pSpline->setFitTol(1.5);

Start and end fit tangents

Start and end tangents define the tangent vectors of the first and the last points of the spline.

To get the start and end tangents of the spline, use the getFitTangents() method, which requires two references to the OdGeVector3d objects through which the tangents will be returned. For example:


// Define the variables
OdGeVector3d pStartTan;
OdGeVector3d pEndTan;
// Get the tangents
pSpline->getFitTangents(pStartTan, pEndTan);
// Display the tangent vectors
odPrintConsoleString(L"\nStart tangent vector: %f %f %f", pStartTan.x, pStartTan.y, pStartTan.z);
odPrintConsoleString(L"\nEnd tangent vector: %f %f %f", pEndTan.x, pEndTan.y, pEndTan.z);

To set the start and end tangents of the spline, use the setFitTangents() method, which requires two references to the OdGeVector3d objects of the new tangent vectors. For example:


pSpline->setFitTangents(OdGeVector3d(1.0, 2.0, 0), OdGeVector3d(0.0, 1.0, 0));

Getting and setting the fit data

To get the fit data, use the getFitData() method, which requires six parameters through which the fit data will be returned: reference to an OdGePoint3dArray object as an array of fit points, reference to an integer value as the spline degree, reference to a double value as the fit tolerance, reference to a boolean value which becomes 'true' if tangents are used, and two references to OdGeVector3d objects to specify start and end tangent vectors. For example:


// Declare variables
OdGePoint3dArray fitPoints;
int degree;
double fitTolerance;
bool tangentsExist;
OdGeVector3d pStartTan;
OdGeVector3d pEndTan;
// Get fit data
pSpline->getFitData(fitPoints, degree, fitTolerance, tangentsExist, pStartTan, pEndTan);
// Display fit data
for (int i = 0; i < fitPoints.size(); i++)
  odPrintConsoleString(L"\nFit point %d coordinates: %f %f %f", i, fitPoints[i].x, fitPoints[i].y, fitPoints[i].z);
odPrintConsoleString(L"\nSpline degree is %d", degree);
odPrintConsoleString(L"\nSpline fit tolerance is %f", fitTolerance);
if (tangentsExist)
{
  odPrintConsoleString(L"\nStart tangent vector: %f %f %f", pStartTan.x, pStartTan.y, pStartTan.z);
  odPrintConsoleString(L"\nEnd tangent vector: %f %f %f", pEndTan.x, pEndTan.y, pEndTan.z);
}

To set the fit data, use the setFitData() method, which requires five parameters: reference to an OdGePoint3dArray object as an array of fit points, integer value as the spline degree, double value as the fit tolerance, and two references to OdGeVector3d objects to specify start and end tangent vectors. For example:


/* Declare variables */
// Declare array of fit points
OdGePoint3d point = OdGePoint3d (0,0,0);
OdGePoint3dArray fitPoints;
fitPoints.push_back(point + OdGeVector3d(0.0, 0.0, 0.0));
fitPoints.push_back(point + OdGeVector3d(3.0, 7.0, 0.0));
fitPoints.push_back(point + OdGeVector3d(5.0, 2.0, 0.0));
fitPoints.push_back(point + OdGeVector3d(10.0, 10.0, 0.0));
// Declare degree
int degree = 3;
// Declare fit tolerance
double fitTolerance = 0.0;
// Declare start tangent
OdGeVector3d pStartTan = OdGeVector3d(0.0, 0.0, 0.0);
OdGeVector3d pEndTan = OdGeVector3d(1.0, 0.0, 0.0);
// Set fit data 
pSpline->setFitData(fitPoints, degree, fitTolerance, pStartTan, pEndTan);

Removing the fit data

To purge all fit data, use the purgeFitData() method, which removes all fit points, and clears tangents and fit tolerance. For example:


pSpline->purgeFitData();

See Also

Working with Splines

Overview of Splines

Specific Properties of Splines

Computed Properties of Splines

Working with NURBS Data

Example of Working with Splines

Copyright © 2002 – 2021. Open Design Alliance. All rights reserved.