The parameter of a lightweight polyline is the relative factor measured from 0.0 to 1.0 for each segment. The value 0.0 defines the start point, and the value 1.0 defines the end point for a segment. A value between 0.0 and 1.0 defines a point inside the segment. When a segment is linear, the parameter defines the distance related to the segment length. When a segment is circular, the parameter defines the angle related to the segment total angle. The parameter determines the significant properties computed at its value (features). In the following examples, the pLWPL variable stores a pointer to the lightweight polyline object.
The Start and End parameters define the available range of variation. The start parameter defines the start point of the first segment of the lightweight polyline and equals 0.0. The end parameter defines the final point of the last segment of the lightweight polyline and equals the number of segments multiplied by 1.0. When a lightweight polyline is open, the final point is the last vertex. When a lightweight polyline is closed, the final point is the first vertex. A value between the start and end parameters defines a point on the polyline curve. An each integer parameter value (1, 2, 3, etc.) defines the corresponding vertex.
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 = pLWPL->getStartParam(vStartParam);
if(eRes == eOk)
OdConsoleString(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 = pLWPL->getEndParam(vEndParam);
if(eRes == eOk)
OdConsoleString(L"\nEnd parameter = %g", vEndParam);
The start and end points are computed at a parameter in three-dimensional coordinates. The start point is computed at the start parameter and coincides with the first vertex. The end point is computed at the end parameter and coincides with the last vertex when the polyline is open, or it coincides with the first vertex when the polyline is closed.
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 = pLWPL->getStartPoint(start);
if(eRes == eOk)
OdConsoleString(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 endOpen, endClose;
pLWPL->setClosed(false);
OdResult eRes = pLWPL->getEndPoint(endOpen);
if(eRes == eOk)
OdConsoleString(L"\nEnd point = (%g,%g,%g)", endOpen.x, endOpen.y, endOpen.z);
pLWPL->setClosed(true);
OdResult eRes = pLWPL->getEndPoint(endClose);
if(eRes == eOk)
OdConsoleString(L"\nEnd point = (%g,%g,%g)", endClose.x, endClose.y, endClose.z);
The first and second derivatives for a point of a lightweight polyline curve are computed at a parameter as vectors in three-dimensional coordinates. Derivatives are changed along the curve relative to the linear or circular 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 polyline 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 += 0.1)
{
if((eRes = pLWPL->getFirstDeriv(vParam, vecFirst)) == eOk)
OdConsoleString(L"\nFirst derivative vector (at %g) = (%g,%g,%g)", vParam, ecFirst.x, vecFirst.y, vecFirst.z);
}
To get the second derivative, use the getSecondDeriv() method which requires a parameter value specifying a point on the polyline 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 += 0.1)
{
if((eRes = pLWPL->getSecondDeriv(vParam, vecSecond)) == eOk)
OdConsoleString(L"\nSecond derivative vector (at %g) = (%g,%g,%g)", vParam, vecSecond.x, vecSecond.y, vecSecond.z);
}
The distance along a lightweight polyline can be computed from the first vertex to a point at a parameter. The object takes into account total lengths of those segments which are previous to the segment on which point lies. The end parameter defines the total length of the polyline curve. An integer parameter value between the start and end parameter defines the total length of corresponding segments. The lightweight polyline calculates the line length or arc length subject to the segment type. The lightweight polyline 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 lightweight polyline 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 += 0.1)
{
if((eRes = pLWPL->getDistAtParam(vParam, vLength)) == eOk)
OdConsoleString(L"\nLength (at %g) = %g", vParam, vLength);
}
To compute the total length, use the end parameter value. For example:
double vTotalLength;
OdResult eRes = pLWPL->getDistAtParam(vEndParam, vTotalLength);
if(eRes == eOk)
OdConsoleString(L"\nPolyline length = %g", vTotalLength);
To compute the length of each segment, use integer parameter values. For example:
int vNum, vSegments;
double vLength, vSumLength;
OdResult eRes
if((eRes = pLWPL->getDistAtParam(vEndParam, vLength)) == eOk)
{
vSegments = (int)Length;
for(vSumLength = 0.0, vNum = 1 ; vNum <= vSegments ; vNum++, vSumLength = vLength)
{
if((eRes = pLWPL->getDistAtParam((double)vNum, vLength)) == eOk)
OdConsoleString(L"\nSegment(%d) length = %g", vNum, (vLength - vSumLength));
}
}
To get the parameter at a distance, use the getParamAtDist() method which requires a positive double value specifying the displacement along the lightweight polyline 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;
if((eRes = pLWPL->getEndParam(vParam)) == eOk)
if((eRes = pLWPL->getDistAtParam(vParam, vLength)) == eOk)
while(vLength > 0.0)
{
OdConsoleString(L"\nParameter (at %g) = %g", vLength, vParam);
vLength -= 0.3;
if((eRes = pLWPL->getParamAtDist(vLength, vParam)) != eOk) break;
}
A point on a lightweight polyline can be computed at a parameter in three-dimensional coordinates. The lightweight polyline object allows 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, to calculate middle points on segments:
int vNum, vSegments;
OdResult eRes;
OdGePoint3d middle;
vSegments = pLWPL->numVerts();
for(vNum = 0 ; vNum < vSegments ; vNum++)
{
if((eRes = pLWPL->getPointAtParam((double)vNum + 0.5, middle)) == eOk)
OdConsoleString(L"\nSegment (%d) middle point = (%g,%g,%g)", vNum, middle.x, middle.y, middle.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 the lightweight polyline, errors occur. For example:
double vParam;
int index, vertices;
OdResult eRes;
OdGePoint3d point;
vertices = pLWPL->numVerts();
for(index = 0 ; index < vertices ; index++)
{
pLWPL->getPointAt(index, point);
if((eRes = pLWPL->getParamAtPoint(point, vParam)) == eOk)
OdConsoleString(L"\nParameter(%d) = %g", index, vParam);
}
The lightweight polyline object calculates the area assuming that the curve is closed. When a lightweight polyline is open, it calculates the area between the polyline curve and the line connecting the first and last vertex.
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 = pLWPL->getArea(vArea);
if(eRes == eOk)
OdConsoleString(L"\nPolyline area = %g", vArea);
Working with Lightweight Polylines
Specific Lightweight Polyline Properties
Example of Working with the Lightweight Polyline Object
Copyright © 2002 – 2020. Open Design Alliance. All rights reserved.
|