In the Ge library there are four classes that allow you to work with intersected entities:
OdGeCurveCurveInt2d
— Represents intersections between 2D curves.OdGeCurveCurveInt3d
— Represents intersections between 3D curves.OdGeCurveSurfInt
— Represents intersections between a 3D curve and 3d surface.GeSurfSurfInt
— Represents intersections between 3D surfaces.All the classes share similar functionality, however there are some differences.
Note:
There are two types of intersections: intersection points and intersection curves.
Each intersection has its own index. Points and curves have independent numerations for curve intersections
for the OdGeCurveCurveInt2d
and OdGeCurveCurveInt3d
classes
and shared numerations for OdGeCurveSurfInt
and OdGeSurfSurfInt
(see examples and images below).
Ends of the overlapping intersections are not returned as separate intersection points. Intersection curves can touch each other at their ends.
An alternate way to calculate intersections is to use the intersectWith()
methods which are implemented for the majority
of curve and surface entities.
The OdGeCurveCurveInt2d
and OdGeCurveCurveInt3d
classes are used for working with
intersected curves. The majority of the properties are similar for both classes, therefore only properties of the
OdGeCurveCurveInt3d
class are included below.
To create anOdGeCurveCurveInt3d
object, you can use one of the OdGeCurveCurveInt3d()
constructors:
OdGeCurveCurveInt3d::OdGeCurveCurveInt3d();
— Default constructor. Creates
an object with no valid data assigned to it.OdGeCurveCurveInt3d::OdGeCurveCurveInt3d(const OdGeCurveCurveInt3d& source)
— Copies an intersection class between 3d curves.OdGeCurveCurveInt3d::OdGeCurveCurveInt3d(const OdGeCurve3d& curve1, const OdGeCurve3d& curve2, const OdGeVector3d& planeNormal = OdGeVector3d::kIdentity, const OdGeTol tol = OdGeContext::gTol)
—
Creates an intersection class between two input curves with respect to the specified tolerance.OdGeCurveCurveInt3d::OdGeCurveCurveInt3d(const OdGeCurve3d& curve1, const OdGeCurve3d& curve2, const OdGeInterval& range1, const OdGeInterval& range2, const OdGeVector3d& planeNormal = OdGeVector3d::kIdentity, const OdGeTol tol = OdGeContext::gTol)
—
Creates an intersection class between two input curves limited by the corresponding parametric ranges with respect to the specified tolerance.The OdGeCurveCurveInt3d
class provides a set of methods for working with intersections between 3d curves. The curve1()
, curve2()
, getIntRanges()
, tolerance()
,
numIntPoints()
, intPoint()
, getIntParams()
, getPointOnCurve1()
,
and getPointOnCurve2()
methods are used to obtain first and second curves of the intersection class, intersection ranges, tolerance, intersection points and their count,
intersection parameters, and intersection points on the first and second curves.
To set intersection class properties, use the set()
methods that define multiple
properties of the intersection class simultaneously. For example:
OdGeCurveCurveInt3d intersector(curve1, curve2);
OdGeTol tol = intersector.tolerance();
double intParam1, intParam2;
for (int intIndex = 0; intIndex < intersector.numIntPoints(); ++intIndex) //cycle for all intersection points
{
// get intersection point, params and corresponding points on input curves for the intIndex-th intersection
OdGePoint3d intPoint = intersector.intPoint(intIndex);
intersector.getIntParams(intIndex, intParam1, intParam2);
OdGePointOnCurve3d intPnt1, intPnt2;
intersector.getPointOnCurve1(intIndex, intPnt1);
intersector.getPointOnCurve2(intIndex, intPnt2);
}
intersector.set(curve3, curve4);
Some input curves may not intersect but lie on top of each other. In this case curves have no intersection
points but instead have overlapping parametric ranges. The overlapCount()
method is used
to retrieve the number of places where curves overlap. You can also use the getOverlapRanges()
method to retrieve parametric ranges of both curves at the specified intersection index (0 ≤ index < OdGeCurveCurveInt3d::overlapCount()
).
for (int overlapIdx = 0; overlapIdx < intersector.overlapCount(); ++overlapIdx) //cycle for all overlaps
{
OdGeInterval range1, range2;
intersector.getOverlapRanges(overlapIdx, range1, range2); //get ranges of the input curves, where j-th overlap is present
}
You can use the changeCurveOrder()
method to swap the first and second curve.
The orderWrt1()
and orderWrt2()
methods are used to order the intersection points so they correspond to
increasing parameter values of the first and second curve respectively.
intersector.changeCurveOrder();
OdGeCurveCurveInt3d int1 = intersector.orderWrt1();
OdGeCurveCurveInt3d int2 = intersector.orderWrt2();
Polylines, composite curves, nurbs curves, etc. can self intersect.
You can find 2d or 3d curve self intersections by passing it to OdGeCurveCurveInt2d
or
OdGeCurveCurveInt3d
classes as both parameters.
OdGeCurveCurveInt3d intersector(curve, curve);
One or several overlap ranges are returned as well as one or several intersection points in the self intersections. Note that 3D points may duplicate, while every parameters pair is unique. For example, on the following picture two equal 3D intersection points with parameter pairs (1, 2) and (2, 1) are returned.
Duplicate 3D points may also be returned for two different curves if one of them is self-intersecting. For example, on the picture below two equal 3D intersection points with parameter pairs (1, 0.5) and (2, 0.5) are returned.
The OdGeSurfSurfInt
class is used for working with intersected surfaces.
To create an OdGeSurfSurfInt
object, you can use one of the OdGeSurfSurfInt()
constructors:
OdGeSurfSurfInt::OdGeSurfSurfInt();
— Default constructor. Creates
an object with no valid data assigned to it.OdGeSurfSurfInt::OdGeSurfSurfInt(const OdGeSurfSurfInt& source)
— Copies an intersection class between surfaces.OdGeSurfSurfInt::OdGeSurfSurfInt(const OdGeSurface& srf1, const OdGeSurface& srf2, const OdGeTol tol = OdGeContext::gTol)
—
Creates an intersection class between two input surfaces with respect to the specified tolerance.The OdGeSurfSurfInt
class provides a set of methods for working with intersections between surfaces. The surface1()
, surface2()
, tolerance()
, intCurve()
,
intParamCurve()
, intPoint()
, getIntPointParams()
, and numIntCurves()
methods are used to obtain first and second surfaces of an intersection class, intersection tolerance, intersection ranges, intersection curve between surfaces,
intersection point, intersection point with parameters, and the number of intersection curves.
Note that the intCurve()
and intParamCurve()
methods return raw pointers to the curve,
so it is your responsibility to delete the returned curves. Also these methods return NULL on the second call, as the same curve cannot be retrieved twice.
To set intersection properties, use the set()
method that defines multiple
properties of the intersection class simultaneously. For example:
OdGeCone cone1(1.0, 1.0, OdGePoint3d(1.0, 1.0, 0.0), 3.0, OdGeVector3d(0.0, 1.0, 0.0));
OdGeCone cone2(-1.0, 1.0, OdGePoint3d(1.0, 1.0, 0.0), 3.0, OdGeVector3d(0.0, 1.0, 0.0));
OdGeSurfSurfInt surfIntersector(cone1, cone2);
OdGeTol tolerance = surfIntersector.tolerance();
for (int intIndex = 0; intIndex < surfIntersector.numResults(); ++intIndex) //cycle for all intersections
{
OdGeIntersectionError status;
if (surfIntersector.getDimension(intIndex, status) == 0) //get dimension of the intIndex-th intersection: point – 0, curve – 1
{
double param1, param2;
surfIntersection.getIntParams(intIndex, param1, param2, status); //get parameters of intIndex-th intersection point
}
else
{
OdGeCurve3d* curve3d = surfIntersection.intCurve(intIndex, false, false, status); //get intIndex-th intersection 3d curve
OdGeCurve2d* curve2d = surfIntersection.intParamCurve(intIndex, false, true/*false*/, status); //get intIndex-th intersection 2d curve on first (second) input surface
delete curve3d;
delete curve2d;
}
}
Also in the code example above, the getDimension()
method is used to determine the dimension of the current intersection.
Some input surfaces may not intersect but instead lie on top of each other. You can use the haveOverlap()
method to
determine whether input surfaces overlap. This method returns true
if surfaces overlap, or false
otherwise.
The method requires the OdGeIntersectError& status
parameter that represents the result of the method execution.
This parameter is set to the kXXOk
value if the method finishes successfully or a corresponding error code otherwise.
Intersection error codes:
enum OdGeIntersectError
{
kXXOk, // OK.
kXXIndexOutOfRange, // Index out of range.
kXXWrongDimensionAtIndex, // Wrong dimension at index.
kXXUnknown // Unknown.
};
The following example shows how to determine if surfaces overlap each other:
OdGeIntersectError status;
bool bOverlap = surfIntersection.haveOverlap(status);
You can retrieve an intersection dimension for a specified intersection with the getDimension()
method.
The method requires a zero-based index of the intersection and sets the result of method execution for the OdGeIntersectError& status
parameter. The returned value can be:
int dimension = surfIntersection.getDimension(intIndex, result);
The OdGeCurveSurfInt
class is used for working with intersections between a surface and curve.
To create anOdGeCurveSurfInt
object, you can use one of the OdGeCurveSurfInt()
constructors:
OdGeCurveSurfInt::OdGeCurveSurfInt();
— Default constructor. Creates
an object with no valid data assigned to it.OdGeCurveSurfInt::OdGeCurveSurfInt(const OdGeCurveSurfInt& source)
— Copies an intersection class between a surface and curve.OdGeCurveSurfInt::OdGeCurveSurfInt(const OdGeCurve3d& curve, const OdGeSurface& surf, const OdGeTol tol = OdGeContext::gTol)
—
Creates an intersection class between an input curve and surface with respect to the specified tolerance.The OdGeCurveSurfInt
class provides a set of methods for working with intersections between a curve and surface. The surface()
, curve()
, tolerance()
, numResults()
,
numIntPoints()
, intPoint()
, getIntParams()
, getPointOnCurve()
,
getPointOnSurface()
, and intParamCurve()
methods are used to obtain the surface and curve of an intersection class,
intersection tolerance, intersection ranges, tolerance, intersection curve, number of intersections (points + overlaps),
individual intersection points, intersection parameters, intersection point on the curve, intersection point on the surface, and parameter on the surface.
To set intersection class properties, use the set()
method which defines multiple
properties of the intersection class simultaneously. For example:
OdGePlane plane = OdGePlane::kXYPlane;
OdGeLine3d line(OdGePoint3d(-1.0, -1.0, -1.0), OdGePoint3d(1.0, 1.0, 1.0));
OdGeCurveSurfInt curveSurfIntersector(line, plane);
OdGeCurve3d* pIntCurve = curveSurfIntersector.curve();
OdGeSurface* pIntSurf = curveSurfIntersector.surface();
OdGeTol tolerance = curveSurfIntersector.tolerance();
OdGeIntersectError status;
int numPoints = curveSurfIntersector.numIntPoints(status);
for (int intIndex = 0; intIndex < curveSurfIntersector.numResults(); ++intIndex) //cycle for all intersections
{
if (curveSurfIntersector.getDimension(intIndex, status) == 0) //get dimension of the i-th intersection: point – 0, curve – 1
{
OdGePoint3d intPt = curveSurfIntersector.intPoint(intIndex, status); //get parameters of i-th intersection point
}
}
A curve can intersect or overlap (lie on) a specified surface. The overlapCount()
method allows you to retrieve the number of
places where a curve overlaps the surface. The getOverlapRange()
method retrieves the parametric range of the
overlap specified by overlap index. Both methods require the OdGeIntersectError& status
parameter which represents the result of method execution.
This parameter is set to the kXXOk
value if the methods finishes successfully or a corresponding error code otherwise.
OdGeInterval range;
OdGeIntersectError status;
for (int overlapIdx = 0; overlapIdx < curveSurfIntersection.overlapCount(); ++overlapIdx) //cycle for all intersection curves, i.e. overlaps of the input curves
{
curveSurfIntersection.getOverlapRange(overlapIdx, range, status);
}
You can retrieve an intersection dimension for a specified intersection class with the getDimension()
method.
The method requires a zero-based index of the intersection and sets the result of method execution for the OdGeIntersectError& status
parameter. The returned value can be:
int dimension = curveSurfIntersection.getDimension(intIndex, status);
Another way to intersect entities is to use the intersectWith()
methods which are available for the most common types of curve and surface entities.
To get more information about curves and surfaces, see Working with Curves and Working with Surfaces.
For curve-curve or curve-surface intersections, the intersectWith()
method returns true
if this entity and the passed entity have at least one intersection point (intersection curves are ignored). The intersectWith()
methods receive intersection points if the true
value is returned.
For surface-surface intersections, the intersectWith()
method returns true
if this entity and the passed entity have an intersection curve, which is received in the parameter intLine
.
Note: The intersectWith()
methods for two linear entities, and for planar and linear entities, retrieve intersection points even if one linear
entity lies on the continuation of the entities and the returned value is false
.
OdGePoint3d p1, p2;
bool intersect = circle.intersectWith(line, numInt, p1, p2, 1e-10);
if (numInt == 0)
doSomething();
if (numInt == 1)
doSomething(p1);
if (numInt == 2)
doSomething(p1, p2);
Copyright © 2002 – 2020. Open Design Alliance. All rights reserved.
|