Message 1 of 2
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
AcDbCurve::GetClosedPointTo this function have an argument "extend" and AcGeCurve3d::ClosestPointTo don't have it
Solved! Go to Solution.
AcDbCurve::GetClosedPointTo this function have an argument "extend" and AcGeCurve3d::ClosestPointTo don't have it
Solved! Go to Solution.
This is a simple possible implementation. It uses tangential rays at the start or endpoint of the curve to extent the curve.
I haven't tested the code. Use at your own risk!
AcGePoint3d closestPointTo(const AcGeCurve3d gecrv, const AcGePoint3d& pt, bool bExtent)
{
AcGePoint3d ptClose = gecrv.closestPointTo(pt);
if (bExtent)
{
// Check whether ptClose is equal to the start- or endpoint of the curve
AcGeInterval intrvl;
AcGePoint3d ptStart, ptEnd;
double parStart, parEnd;
gecrv.getInterval(intrvl, ptStart, ptEnd);
intrvl.getBounds(parStart, parEnd);
bool bHasStart = intrvl.isBoundedBelow();
bool bHasEnd = intrvl.isBoundedAbove() ;
AcGeVector3d dir(pt-ptClose), vTangent;
AcGeVector3dArray arrDerivs;
if (bHasStart && (ptClose==ptStart))
{
gecrv.evalPoint(parStart, 1, arrDerivs);
vTangent = -arrDerivs[0]; // points tangential away from ptStart
}
else if (bHasEnd && (ptClose==ptEnd))
{
gecrv.evalPoint(parEnd, 1, arrDerivs);
vTangent = arrDerivs[0]; // points tangential away from ptEnd
}
else
return ptClose; // Not start or endpoint. ptClose is already the closest point.
double dotProd = dir.dotProduct(arrDerivs[0]);
if (dotProd > 0.0)
{
// ptClose is "in front of" ptStart or "behind" ptEnd
// Calculate the closest point to the ray starting at point ptClose with direction arrDerivs[0]
AcGeRay3d ray(ptClose, vTangent);
ptClose = ray.closestPointTo(pt);
// This is the most simple way to extend a curve using a tangetial ray.
// You might want to use a different curve.
}
}
return ptClose;
}