# Differences

This shows you the differences between two versions of the page.

 — developer:sdksamples:crvarclengthpoint [2015/09/14] (current) Line 1: Line 1: + ====== Finding Points on Curves at Arc Length Distances ====== + ====== ​ C++ ====== + > **Summary:​** //​Demonstrates how to find points that are a specified distance from the start of curves using the Rhino SDK.// + + =====Question===== + For a given length from the beginning of a curve, how would I get a curve'​s parameter at this point? + + =====Answer===== + The two function on ON_Curve that are useful for determining the parameter of the point on a curve that is a prescribed arc length distance from the start of a curve are: + + * ON_Curve::​GetNormalizedArcLengthPoint + * ON_Curve::​GetNormalizedArcLengthPoints + + To use these functions, you need to calculate a normalized arc length parameter. That is, a parameter on the curve where 0.0 = the start of the curve, 0.5 = the midpoint of the curve, and 1.0 = the end of the curve. + + Note, if you want to determine the parameter of the point on a curve that is a prescribed arc length distance from the end of a curve, just reverse the curve before calling one of the above curve members. + + The following code sample demonstrates how to use these functions. + + ===== C++ ===== + + CRhinoCommand::​result CCommandTest::​RunCommand( const CRhinoCommandContext&​ context ) + { + CRhinoGetObject go; + go.SetCommandPrompt( L"​Select curve" ); + go.SetGeometryFilter( CRhinoGetObject::​curve_object ); + go.GetObjects( 1, 1 ); + if( go.CommandResult() != success ) + return go.CommandResult();​ + + const CRhinoObjRef&​ obj_ref = go.Object(0);​ + const ON_Curve* crv = obj_ref.Curve();​ + if( 0 == crv ) + return failure; + + double crv_length = 0.0; + if( !crv->​GetLength(&​crv_length) ) + return failure; + + CRhinoGetNumber gn; + gn.SetCommandPrompt( L"​Length from start" ); + gn.SetLowerLimit( 0.0, TRUE ); + gn.SetUpperLimit( crv_length, TRUE ); + gn.GetNumber();​ + if( gn.CommandResult() != success ) + return gn.CommandResult();​ + + // Cook up a normalized arc length parameter, ​ + // where 0.0 <= s <= 1.0. + double length = fabs( gn.Number() ); + double s = 0.0; + if( length == 0.0 ) + s = 0.0; + else if( length == crv_length ) + s = 1.0; + else + s = length / crv_length; + + // Get the parameter of the point on the curve that is a + // prescribed arc length from the start of the curve. + double t = 0.0; + if( crv->​GetNormalizedArcLengthPoint(s,​ &t) ) + { + ON_3dPoint pt = crv->​PointAt( t ); + context.m_doc.AddPointObject( pt ); + context.m_doc.Redraw();​ + } + + return success; + } + ​ + + + {{tag>​Developer}}