Quantcast
Viewing all articles
Browse latest Browse all 564

How to triangulate arcs

Author:Akos Somorjai
Posted: Sun Dec 18, 2016 11:40 am (GMT+1)


Ralph Wessel wrote:
IanTr wrote:
According to the API doc, ACAPI_Goodies (APIAny_TriangulatePolyID, ...) only accept polygons that has no arc segments. The code snippet on that page also shows it skips over nArcs > 0. I was just wondering if there are functions/methods that I missed looking through the samples that handles triangulation of arcs.

You could facet the arc edges to the required level of precision first.


Ian,

Here comes a sample which shows how to do that with the help of the Geometry module.

Code:
#include "GenArc2DData.h"
#include "Ellipse2DData.h"

/*----------------------------------------------------------**
**   Gets the current ARCHICAD settings for arc division      **
**----------------------------------------------------------*/
static double GetMaxDiff ()
{
   double   maxDiff = EPS;
   if (ACAPI_Environment (APIEnv_GetExportToleranceID, &maxDiff) != NoError) {
      API_MagicWandInfo   mwi = {0};
      if (ACAPI_Environment (APIEnv_GetMagicWandSetsID, &mwi) != NoError)
         maxDiff = EPS;
      else
         maxDiff = mwi.arcDiff;
   }

   return maxDiff;
}

/*----------------------------------------------------------**
**   Divides an arc according to the currect AC settings      **
**----------------------------------------------------------*/
static GSErrCode DivideArc (const API_Coord& orig, double r,
                     double begAng, double endAng, bool reflected,
                     double ratio, bool elliptic,
                     USize * nCo, Coord** hCo)
{
   GenArc genArc;

   if (elliptic) {
      genArc.SetToEllipseArc (Geometry::Ellipse ((const Coord &)orig, r, ratio, 0.0), begAng, endAng, reflected);
   } else {
      genArc.SetToCircleArc ((const Coord &)orig, r, begAng, endAng, reflected);
   }
   Geometry::DivideEllArcToCo  (genArc, GetMaxDiff (), hCo, nCo);

   return NoError;
}

/*----------------------------------------------------------**
**   Writes out a Circular/Elliptic Arc, divided            **
**----------------------------------------------------------*/
static GSErrCode   DWF_WrDividedArc (const API_Coord& orig, double r,
                             double begAng, double endAng, bool reflected = false,
                             double ratio = 1.0, bool elliptic = false)
{
   USize   nCo = 0;
   Coord   **hCo = reinterpret_cast<Coord **> (BMhAll (0));
   GSErrCode lastErr = DivideArc (orig, r, begAng, endAng, reflected, ratio, elliptic, &nCo, hCo);
   if (lastErr != NoError) {
      BMhFree ((GSHandle) hCo);
      return lastErr;
   }

   // ...

   BMhFree ((GSHandle) hCo);

   return lastErr;
}


Regards, Akos


Viewing all articles
Browse latest Browse all 564

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>