Code sample Home

Get intersection points of a line with TIN object.
void DemoTinInterLine (HANDLE hLcWnd)
{
  HANDLE hDrw, hBlock, hTIN, hLine, hPnt, hPline, hXline;
  WCHAR* szFileName = L"C:/Data/TIN/SimpleTIN.lcd";
  WCHAR* szTinName = L"The test TIN 2";
  int    Key, nPnts, i;
  double X0, Y0, X1, Y1, X, Y, Z, Z0, Dist, dY, VertScale;

  // get drawing and block, linked with CAD window
  hDrw = lcPropGetHandle( hLcWnd, LC_PROP_WND_DRW );
  // load drawing from a file
  lcDrwLoad( hDrw, szFileName, hLcWnd );
  hBlock = lcPropGetHandle( hLcWnd, LC_PROP_WND_VIEWBLOCK );
  // get TIN with specified name
  hTIN = lcBlockGetTIN( hBlock, szTinName );
  if (hTIN != 0){
    // get intersection line
    Key = 123;
    hLine = lcBlockGetEntByKey( hBlock, Key );
    if (lcEntType( hLine, LC_ENT_LINE ) == TRUE){
      X0 = lcPropGetFloat( hLine, LC_PROP_LINE_X0 );
      Y0 = lcPropGetFloat( hLine, LC_PROP_LINE_Y0 );
      X1 = lcPropGetFloat( hLine, LC_PROP_LINE_X1 );
      Y1 = lcPropGetFloat( hLine, LC_PROP_LINE_Y1 );
      // find intersection points of the line with the TIN
      nPnts = lcTIN_InterLine( hTIN, X0, Y0, X1, Y1 );
      if (nPnts >= 2){
        // add the points into the drawing
        // also add a polyline of vertical section
        dY = 85.0;
        VertScale = 10.0;
        hPline = lcBlockAddPolyline( hBlock, 0, false, false );
        for (i=0; i<nPnts; ++i){
          if (lcTIN_InterGetPoint( hTIN, i, &X, &Y, &Z ) == TRUE){
//            hPnt = lcBlockAddPoint( hBlock, X, Y );
            hPnt = lcBlockAddPoint2( hBlock, X, Y, LC_POINT_PIXEL|LC_POINT_CIRCLE, -0.5 );
            if (hPnt != 0){
              lcPropPutFloat( hPnt, LC_PROP_ENT_Z, Z );
              if (i == 0){
                X0 = X;
                Y0 = Y;
                Z0 = Z;
                Dist = 0.0;
                hXline = lcBlockAddXline( hBlock, X0, Y0-dY, 0.0, false );
                lcPropPutStr( hXline, LC_PROP_ENT_COLOR, L"92,92,128" );
              }else{
                Dist = _hypot( X-X0, Y-Y0 );
              }
              X1 = X0 + Dist;
              Y1 = Y0 - dY + ((Z - Z0) * VertScale);
              lcPlineAddVer( hPline, 0, X1, Y1 );
              // add a line that links intersection points with polyline vertices
              hLine = lcBlockAddLine( hBlock, X, Y, X1, Y1 );
              lcPropPutStr( hLine, LC_PROP_ENT_COLOR, L"120,90,50" );
              lcEntToBottom( hLine );
            }
          }
        }
        lcPlineEnd( hPline );
      }
      // update view
      lcWndRedraw( hLcWnd );
    }
  }
}
This will create a drawing as shown on the picture below: