Getting the Midpoint of each Polyline Segment using ObjectARX

By Fenton Webb

An AcDbPolyline is derived from AcDbCurve, a curve uses Parameter values to define its geometry. For a Polyline, the Parameter start value is 0 and the end parameter is the total number of vertices –1. Those parameter values can be utilized to quickly and easily work out mid points, like this:

Acad::ErrorStatus getMidPointOnEachSegOfCrv(AcDbCurve *pCurve)        {          if(!pCurve->isKindOf(AcDbCurve::desc()))          {            acutPrintf(L"nSelected entity is not a CURVE derived object");            return Acad::eInvalidInput;          }                   Acad::ErrorStatus es;          double startParam, endParam;          // get the start param, usually it starts at 0 or 1          es = pCurve->getStartParam( startParam );          acutPrintf(L"nstartParam is %fl", startParam);                   // get the end param, for a polyline it's the total number of          // vertex's -1          es =  pCurve->getEndParam( endParam );          acutPrintf(L"nendParam is %fl", endParam);          // now loop the parameters, adding 1.0 each iteration          for(double i=startParam; igetPointAtParam(i+.5, pt);            if (es == Acad::eOk)              acutPrintf(L"n%f,%f,%f", pt[0], pt[1], pt[2]);          }                   return Acad::eOk;        }

Share this:

Like this:

Like Loading…

Comments

6 responses to “Getting the Midpoint of each Polyline Segment using ObjectARX”

  1. Oh no, et tu Fenton!? Your code violates the central tenet of parameterized curves: that parameters are opaque and you should make no assumptions about them. Please, in the name of all that is good and holy, fix this abomination that you have posted by using the “dist” functions as designed and intended.

  2. Fenton Webb Avatar
    Fenton Webb

    Hey Owen!
    feel free to correct it as you see fit! I like to bend the rules, myself.

  3. Hmm, you are a stubborn one. I guess I need to break out the big guns and blog my old QuirkyPolyline sample.

  4. Hi, Fenton!
    Please, double check your’s code:
    for(double i=startParam; i<=endParam; ++i)
    {
    AcGePoint3d pt;
    es = pCurve->getPointAtParam(startParam+.5, pt);
    if (es == Acad::eOk)
    acutPrintf(L”\n%f,%f,%f”, pt[0], pt[1], pt[2]);
    }
    Maybe:
    es = pCurve->getPointAtParam(i+.5, pt);

  5. Fenton Webb Avatar
    Fenton Webb

    Hey Owen!
    that’s really good content, thanks for that.

Leave a Reply

Discover more from Autodesk Developer Blog

Subscribe now to keep reading and get access to the full archive.

Continue reading