Drawings SDK Developer Guide > Working with .dwg Files > Working with Entities > Working with Specific Entitites > Working with Splines > Computed Properties of Splines
Computed Properties of Splines

The parameter of a spline is the relative factor measured in a range, specific for every spline. The parameter determines the significant properties computed at its value (features). In the following examples, the pSpline variable stores a pointer to the spline object.

Start and End Parameters

The Start and End parameters define the available range of variation. The start parameter defines the start point of the spline. The end parameter defines the final point of the spline.

To get the start parameter, use the getStartParam() method which requires a reference to a variable of the double type in which the start parameter value must be saved as an argument and returns the start value through this argument or an error code as a result.
For example:


double vStartParam;
OdResult eRes = pSpline->getStartParam(vStartParam);
if(eRes == eOk)
  odPrintConsoleString(L"\nStart parameter = %g", vStartParam);

To get the end parameter, use the getEndParam() method which requires a reference to a variable of the double type in which the end parameter value must be saved as an argument and returns the end value through this argument or an error code as a result. For example:


double vEndParam;
OdResult eRes = pSpline->getEndParam(vEndParam);
if(eRes == eOk)
  odPrintConsoleString(L"\nEnd parameter = %g", vEndParam);

Start and End Points

The start and end points are computed at a parameter in three-dimensional coordinates. The start point is computed at the start parameter. The end point is computed at the end parameter.

To get the start point, use the getStartPoint() method which requires a reference to a variable of the OdGePoint3d type in which the start point instance must be saved as an argument and returns the computed three-dimensional point through this argument or an error code as a result. For example:


OdGePoint3d start;
OdResult eRes = pSpline->getStartPoint(start);
if(eRes == eOk)
  odPrintConsoleString(L"\nStart point = (%g,%g,%g)", start.x, start.y, start.z);

To get the end point, use the getEndPoint() method which requires a reference to a variable of the OdGePoint3d type in which the end point instance must be saved as an argument and returns the computed three-dimensional point through this argument or an error code as a result. For example:


OdGePoint3d end;
OdResult eRes = pSpline->getEndPoint(end); 
if(eRes == eOk)
  odPrintConsoleString(L"\nEnd point = (%g,%g,%g)", end.x, end.y, end.z);

First and Second Derivatives

The first and second derivatives for a point of a spline curve are computed at a parameter as vectors in three-dimensional coordinates. Derivatives are changed along the curve relative to its spline segments. The parameter must be between the start and end values. When the parameter value is out of range, errors occur.

To get the first derivative, use the getFirstDeriv() method which requires a parameter value specifying a point on the spline curve as the first argument (double type), requires a reference to a variable (OdGeVector3d type) in which the first derivative vector instance must be saved as the second argument, and returns the computed three-dimensional vector through the second argument or an error code as a result. For example:


double vParam;
OdResult eRes;
OdGeVector3d vecFirst;
for(vParam = vStartParam ; vParam <= vEndParam ; vParam += 10)
{
  eRes = pSpline->getFirstDeriv(vParam, vecFirst);
  if(eRes == eOk) 
    odPrintConsoleString(L"\nFirst derivative vector (at %g) = (%g,%g,%g)", vParam, vecFirst.x, vecFirst.y, vecFirst.z);
}

To get the second derivative, use the getSecondDeriv() method which requires a parameter value specifying a point on the spline curve as the first argument (double type), requires a reference to a variable (OdGeVector3d type) in which the second derivative vector instance must be saved as the second argument, and returns the computed three-dimensional vector through the second argument or an error code as a result. For example:


double vParam;
OdResult eRes;
OdGeVector3d vecSecond;
for(vParam = vStartParam ; vParam <= vEndParam ; vParam += 10)
{
  eRes = pSpline->getSecondDeriv(vParam, vecSecond);
  if(eRes == eOk)
    odPrintConsoleString(L"\nSecond derivative vector (at %g) = (%g,%g,%g)", vParam, vecSecond.x, vecSecond.y, vecSecond.z);
}

Distance and Parameter

The distance along a spline curve can be computed from the first point to a point at a parameter. The end parameter defines the total length of the spline curve. The spline object allows calculating the distance at a parameter and the parameter at a distance.

To get the distance at a parameter, use the getDistAtParam() method which requires a parameter value specifying a point on the spline curve as the first argument (double type), requires a reference to a variable (double type) in which the distance value must be saved as the second argument, and returns the distance through the second argument or an error code as a result. The parameter must be between the start and end values, otherwise errors occur. For example:


double vParam, vLength;
OdResult eRes;
for(vParam = vStartParam ; vParam <= vEndParam ; vParam += 10)
{
  eRes = pSpline->getDistAtParam(vParam, vLength);
  if(eRes == eOk)
    odPrintConsoleString(L"\nLength (at %g) = %g", vParam, vLength);
}

To compute the total length, use the end parameter value. For example:


double vTotalLength;
OdResult eRes; 
eRes= pSpline->getDistAtParam(vEndParam, vTotalLength);
if(eRes == eOk)
  odPrintConsoleString(L"\nspline length = %g", vTotalLength);

To get the parameter at a distance, use the getParamAtDist() method which requires a positive double value specifying the displacement along a spline curve as the first argument (double type), a reference to a variable (double type) in which the parameter value must be saved as the second argument, and returns the parameter value corresponding to the distance through the second argument or an error code as a result. The distance must be between zero and the total length, otherwise errors occur. For example:


double vParam, vLength;
OdResult eRes;
eRes = pSpline->getEndParam(vParam);
if(eRes == eOk)
{
  eRes = pSpline->getDistAtParam(vParam, vLength);
  if(eRes == eOk)
    while(vLength > 0.0)
    {
      odPrintConsoleString(L"\nParameter (at %g) = %g", vLength, vParam);
      vLength -= 10;
      eRes = pSpline->getParamAtDist(vLength, vParam);
      if(eRes != eOk) break;
    }
}

Point and Parameter

A point on a spline curve can be computed at a parameter in three-dimensional coordinates. The spline objects allow calculating the point at a parameter and the parameter at a point.

To get the point at a parameter, use the getPointAtParam() method which requires a parameter value as the first argument of the double type, requires a reference to a variable of the OdGePoint3d type in which the point instance must be saved as the second argument, and returns the computed three-dimensional point through the second argument or an error code as a result. When the parameter value is out of range, errors occur. For example:


double vParam, vStartParam, vEndParam;
OdResult eRes;
OdGePoint3d point;

eRes = pSpline->getStartParam(vStartParam);
eRes = pSpline->getEndParam(vEndParam);
for(vParam = vStartParam ; vParam <= vEndParam; vParam += 10)
{
  if((eRes = pSpline->getPointAtParam(vParam , point)) == eOk)
    odPrintConsoleString(L"\nPoint(%g) = (%g,%g,%g)", vParam, point.x, point.y, point.z);
}

To get the parameter at a point, use the getParamAtPoint() method which requires a point instance of the OdGePoint3d type as the first argument, a reference to a variable of the double type in which the parameter value must be saved as the second argument, and returns the parameter corresponding to the point through the second argument or an error code as a result. When the point is not placed on a spline curve, errors occur. For example:


double vParam;
OdResult eRes;
OdGePoint3d point;

pSpline->getEndPoint(point); 
if((eRes = pSpline->getParamAtPoint(point, vParam)) == eOk)
  odPrintConsoleString(L"\nParameter(end) = %g", vParam);

pSpline->getStartPoint(point); 
if((eRes = pSpline->getParamAtPoint(point, vParam)) == eOk)
  odPrintConsoleString(L"\nParameter(start) = %g", vParam);

Area

The spline object calculates the area assuming that the curve is closed. When a spline curve is open, the object calculates the area between the spline curve and the line connecting the first and last point. The spline object calculates the area if all vertices lie in the same plane (when it is planar).

To get the area, use the getArea() method which requires a reference to a variable of the double type in which the area value must be saved as an argument and returns the area value through this argument or an error code as a result. For example:


double vArea;
OdResult eRes;
eRes = pSpline->getArea(vArea);
if(eRes == eOk)
  odPrintConsoleString(L"\nspline area = %g", vArea);

See Also

Working with Splines

Overview of Splines

Specific Properties of Splines

Working with NURBS Data

Working with Fit Data

Example of Working with Splines

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