How do find the midpoint on a arc?
Solved! Go to Solution.
Solved by chiefbraincloud. Go to Solution.
You can use either the GetPointAtParameter, or the GetPointAtDistance functions. The parameter for an arc is the angle around the circle (from 0) at which you want the Point, but other curve objects (like polylines for instance), would be different.
Dim midbyParam As Point3d = _arc.GetPointAtParameter(_arc.StartAngle + (_arc.TotalAngle / 2))
Dim midbyDist As Point3d = _arc.GetPointAtDist(_arc.Length / 2)
Thanks cheifBrainCloud
That was dead on.
Just to know the midbyParam would get off a little on large arcs. By large arcs I mean around 160' between start and end point, but the block inserted on the arc was always dead on with the midbyDist
That code really isn't a good way to get the midpoint of an arc
because it relies on assumptions about what the parameter of
the curve represents.
It's generally bad design to write code that relies on assumptions
about what exactly the parameter of a Curve represents, mainly
because that code will not work generically on any type of Curve.
So, in cases where you are dealing with different types of Curves,
that type of coding would force you to test each Curve type, and
branch to different code to deal with each.
While you may want to midpoint of an arc now, there is no
justifiable reason to write an arc-specific method to get the
midpoint,when you can just as easily write a generic solution
that returns the midpoint of any non-closed Curve that has a
finite length (e.g., no rays/xlines):
public static Class CurveExtensionMethods
{// excludes error checking for closed & infinite-length curves:
public static Point3d GetMidpoint( this Curve curve )
{double d1 = curve.GetDistanceAtParameter( curve.StartParam );
double d2 = curve.GetDistanceAtParameter( curve.EndParam );
return curve.GetPointAtDist( d1 + ( ( d2 - d1 ) / 2.0 ) );
}
}