Get point at 3D Distance along feature line

Get point at 3D Distance along feature line

izzybabur
Advocate Advocate
3,891 Views
7 Replies
Message 1 of 8

Get point at 3D Distance along feature line

izzybabur
Advocate
Advocate

Hi,

 

I'm trying to get a point at a 3D distance along a feature line. Currently, there is a method under the Feature Line class that allows you to get a point at a distance along the feature line, called " GetPointAtDist ". There is also a method called " Get3dDistanceAtPoint ". 

 

I notice that the GetPointAtDist method gets the point on the feature line at the 2D projected distance, with its associated elevation on the feature line. Is there any documentation on how this method works? Is it measuring a chord distance of the feature line, or taking feature line points and interpolating between them? I am inclined to use the feature line, since I need to work with the true 3D distance of an alignment and its profile, rather than the projected distance. This gets more important when there are curves in the alignment and profile, and I need to measure true 3d distance along the curves with a small amount of tesselation. 

 

Civil 3D's Point Creation Tools using Measure feature line object or Divide feature line object does not work for my purposes (I need points at varying 3D distances along the object). 

 

Does anyone have any suggestions on a better way to do this using the .NET API?

 

Any help would be appreciated! 

Thanks!

0 Likes
Accepted solutions (1)
3,892 Views
7 Replies
Replies (7)
Message 2 of 8

tyronebk
Collaborator
Collaborator
Accepted solution

I am pretty sure the GetPointAtDist() is the 2d distance along the feature.

 

I am sure someone else out there will have a more elegant method, but I would create a new extension method to calculate the point at a 3d distance along the feature. In my quick tests this seems to work.

/// <summary>
/// Returns the 3d length of a feature segment. Will return 0 if
/// used on any invalid feature parameter and calculating more than 1.0 segments
/// at a time will return an incorrect calculation.
/// </summary>
private static double SegmentLength3d( this Feature feature, double startparam, double endparam ) {
	try {
		// get the change in elevation from
		var elevChange = feature.GetPointAtParameter( startparam )[2] - feature.GetPointAtParameter( startparam + endparam )[2];
		// get the 2d length of segment
		var segLen2d = feature.GetDistanceAtParameter( startparam ) - feature.GetDistanceAtParameter( startparam + endparam );
		// pythagorean theorem calulates the 3d length since features don't contain spline elements
		return Math.Sqrt( Math.Pow( elevChange, 2 ) + Math.Pow( segLen2d, 2 ) );
	} catch ( Exception ) {
		return 0;
	}
}

/// <summary>
/// Returns the 3d length of a feature segment. Will return 0 if
/// used on any invalid feature parameter.
/// </summary>
/// <param name="param">The parameter of the feature for which you want the
/// length of the segment following. E.G. entering 1.0 will return the length
/// of the parameter from 1.0 to 2.0.</param>
private static double SegmentLength3d( this Feature feature, double param ) {
	return feature.SegmentLength3d( param, 1.0 );
}

public static Point3d GetPointAtDist3d( this Feature feature, double distance3d ) {
	double totalLen = 0;
	for ( double i = 0.0; i < feature.EndParam; i++ ) {
		var segLen = feature.SegmentLength3d( i );
		if ( distance3d >= totalLen && distance3d < totalLen + segLen ) {
			var distInSeg = distance3d - totalLen;
			return feature.GetPointAtParameter( i + (distInSeg / segLen) );
		} else {
			totalLen += segLen;
		}
	}
	return default;
}
Message 3 of 8

Anonymous
Not applicable

I HAVE THE SAME ISSUE , CAN SOMEONE HELP ME TO SOLVE IT, HOW to do this using the .NET API?

0 Likes
Message 4 of 8

Jeff_M
Consultant
Consultant

@Anonymous what is wrong with the response given by @tyronebk ? It appears to do what you asked for.

Jeff_M, also a frequent Swamper
EESignature
0 Likes
Message 5 of 8

Anonymous
Not applicable

Sir , I m not Much Professional in civil 3d and I don't know how to implement this solution.IF you Could Help me By Telling , How to apply in Civil 3d API.net

0 Likes
Message 6 of 8

Jeff_M
Consultant
Consultant

@Anonymous, create a new class,

public static class FeatureExtensions
{
  //add the code Tyrone provided in his reply
}

 

then, with your Featureline you have a new method to use:

 

   var pt = featureline.GetPointAtDist3d(123.45);
Jeff_M, also a frequent Swamper
EESignature
Message 7 of 8

izzybabur
Advocate
Advocate

Hi @tyronebk 

 

Thanks for your response - and sorry for my late reply. I was using a similar method to calculate 3D distance, but it became a bit challenging for vertical curves and horizontal curves, especially with the spirals. So instead of inquiring from the feature line, for which I have limited control of tessellation, I generated a set of points at much higher sampling resolution that reads directly from the profile and alignment. Note that, in true 3D, the horizontal geometry locations are shifted (i.e. Tangent-to-Spiral), and the shift will continue to accumulate - and the rate at which it accumulates varies with vertical curvature. Also, I had some issues with the rotation matrices so I wrote my own for 3D rotation.

 

Sorry I forgot about this post!

Thanks for your help!

 

izzy

0 Likes
Message 8 of 8

infoEV2AF
Community Visitor
Community Visitor

it would be nice to have a real solution from autodesk, we are'nt all programmer ! with a question being asked 5 years ago and what look like a pretty easy code. You (autodesk) should have implemented a command in civil 3d ! At the price we are paying each years for the subscription this kind of answer are'nt worth it in my opinion.. I'm stock with a feature line of 2000 m who need anchoring at each 2,4 m. It's a pain in the ass without a command and i'm unable to implement you're code 😞 @Jeff_M 

0 Likes