Finding the minimum distance between two objects

1. Create the required objects for the CreateDistanceMin function.

Here we see that there are three methods. The first method was used in this example. We need a CATGeoFactory object, a CATPoint object, a CATCurve object and we need to define a CATSkillVAlue mode.

2. Create a CATGeoFactory object. This object is used to create and retrieve information about objects.

CATGeoFactory* piGeomFactory = ::CATCreateCGMContainer() ;
if (NULL==piGeomFactory) return (1);

3. Create a CATPoint object. To do this, you must create a point using one of the methods contained in the CATGeoFactory object and cast it to a CATPoint.

CATCartesianPoint * piPoint = piGeomFactory->CreateCartesianPoint(5.5,7,-6.5);
CATPoint * pntPointer = (CATPoint*)piPoint;

4. Create a CATCurve object. To do this, you must create two CATPoint objects as outlined in step 3 and use the CATGeoFactory object to create a line, using these two points as inputs. You may use a different curve type contained in CATGeoFActory as long as you cast it as a CATCurve.

CATCartesianPoint * piPoint1 = piGeomFactory->CreateCartesianPoint(3,2,-1);
CATCartesianPoint * piPoint2 = piGeomFactory->CreateCartesianPoint(7,6,8);
CATPoint * pPoint1 = (CATPoint*)piPoint1;
CATPoint * pPoint2 = (CATPoint*)piPoint2;

CATLine * piLine = piGeomFactory->CreateLine(pPoint1, pPoint2);
CATCurve * piCurve = (CATCurve*)piLine;

5. For the last parameter, you have two options, either BASIC or ADVANCED. For our purposes, we are going to use BASIC mode. We are now ready to calculate our minimum distance.

CATDistanceMinPtCrv *mindist = ::CreateDistanceMin(piGeomFactory,piPoint,piCurve,BASIC);

The minimum distance is now accessed using the ->GetDistance() method of the CATDistanceMinPtCrv object. There are several other distance methods that can be used to find the minimum distance between objects using a similar approach to what is outlined here.

CATDistanceMinBodyBody - Find the minimum distance between two bodies

CATDistanceMinCrvCrv - Find the minimum distance between two curves

CATDistanceMinPtSur - Find the minimum distance between a point and a surface