Add a WorkPoint at the intersection of a line and a plane

Top  Previous  Next

Here's a fragment (no error checking) which explains how to do it...

 

       // Get the proxy of the axis

       CComPtr<WorkAxisProxy> pNodeWAZProxy ;

       ZAxisArray[1]->get_Item(2,(IDispatch**)&pNodeWAZProxy);

 

       CComPtr<TransientGeometry> pTransGeom = GetTransGeomPtr () ;   

 

       LinePtr pLine = pNodeWAZProxy->GetLine();

       PointPtr pLineRoot = pLine->GetRootPoint();

       UnitVectorPtr pLineDir = pLine->GetDirection();

       CComPtr <Vector> pvecDir  ;

       hRes = pLineDir->AsVector(&pvecDir);

 

       CComPtr <Line> pZAxis;

       hRes = pTransGeom->CreateLine  (pLineRoot,pvecDir,&pZAxis);

 

       CComPtr<Point> pOrigin;

       CComPtr<Point> p1;

       CComPtr<Point> p2;

 

       // Create 3 points in the XY plane...

       pTransGeom->CreatePoint(0, 0, 0, &pOrigin);

       pTransGeom->CreatePoint(1, 0, 0, &p1);

       pTransGeom->CreatePoint(0, 1, 0, &p2);

 

       // Create the plane with 3 points...

       CComPtr<Plane> pGeomXYPlane;

       hRes = pTransGeom->CreatePlaneByThreePoints(pOrigin, p1, p2, &pGeomXYPlane);

 

       // In general there could me many intersections of a line and a surfaces,

       // With a plane we expeect pObjEnum to contain a single object

       CComPtr <ObjectsEnumerator> pObjEnum;

       hRes = pTransGeom->CurveSurfaceIntersection(pZAxis, pGeomXYPlane, 0.1, &pObjEnum);

 

       TRACE ("There are %d intersections...\n",pObjEnum->Count);

 

       if (pObjEnum->Count < 1) {

           gLogger.Printf(ekErrMsg, "No intersections found...");

           return;

       }

 

       CComPtr <Point> pIntersectionPoint;

       hRes = pObjEnum->get_Item(1,(IDispatch**)&pIntersectionPoint);

 

       TRACE("Intersection at %.2f %.2f %.2f \n",

             pIntersectionPoint->GetX(),

             pIntersectionPoint->GetY(),

             pIntersectionPoint->GetZ());

 

       CComPtr<WorkPoints> pWorkPoints;

       hRes = pAssemblyCompDef->get_WorkPoints(&pWorkPoints);

 

       CComPtr <WorkPoint> pInterWorkPoint;

       pWorkPoints->AddFixed (pIntersectionPoint,FALSE,&pInterWorkPoint);

 

       CComBSTR bstrPointName("ZeroPoint");

       hRes = pInterWorkPoint->put_Name(bstrPointName);

 

 

Text, images and diagrams © 2021 Owen F. Ransen. All rights reserved. (But copy the source code as much as you want!)