How to implement AcDbCurve::GetClosedPointTo function using AcGeCurve3d

How to implement AcDbCurve::GetClosedPointTo function using AcGeCurve3d

nam_h_tran
Advocate Advocate
325 Views
1 Reply
Message 1 of 2

How to implement AcDbCurve::GetClosedPointTo function using AcGeCurve3d

nam_h_tran
Advocate
Advocate

AcDbCurve::GetClosedPointTo this function have an argument "extend" and AcGeCurve3d::ClosestPointTo don't have it

0 Likes
Accepted solutions (1)
326 Views
1 Reply
Reply (1)
Message 2 of 2

tbrammer
Advisor
Advisor
Accepted 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;
}

 


Thomas Brammer ● Software Developer ● imos AGLinkedIn
If an answer solves your problem please [ACCEPT SOLUTION]. Otherwise explain why not.

0 Likes