This document is archived and information here might be outdated. Recommended version. |
ArcObjects Help for .NET developers > ArcObjects namespaces > Geometry > ESRI.ArcGIS.Geometry > Interfaces > IR > IRay Interface > IRay.Intersects Method (ArcObjects .NET 10.5 SDK) |
Indicates if the ray intersects the target geometry.
[Visual Basic .NET] Public Function Intersects ( _ ByVal targetGeometry As IGeometry _ ) As Boolean
[C#] public bool Intersects ( IGeometry targetGeometry );
[C++]
HRESULT Intersects(
IGeometry* targetGeometry,
VARIANT_BOOL* intersectsTarget
);
[C++]
Parameters targetGeometry
targetGeometry is a parameter of type IGeometry intersectsTarget [out, retval] intersectsTarget is a parameter of type VARIANT_BOOL
Implemented for Points, Multipoints, Polylines, Polygons, Envelopes, and Multipatches.
This method is intended to be called against top-level geometries only (Point, Multipoint, Polyline, Polygon, Envelope, MultiPatch). To call this method against a Segment/Path or Ring, first add the part to a Polyline or Polygon container, respectively, and then call this method against the container.
public static void TestIntersection()
{
ILine line = new LineClass();
line.FromPoint=GetPoint();
line.ToPoint=GetPoint();
IRay ray = new RayClass();
ray.Origin=line.FromPoint;
ray.Vector=ConstructVector3D(line.ToPoint.X - line.FromPoint.X, line.ToPoint.Y - line.FromPoint.Y, line.ToPoint.Z - line.FromPoint.Z);
IGeometry multiPatchGeometry=GetMultiPatchGeometry();
bool intersects = ray.Intersects(multiPatchGeometry);
//intersects=true
}
private static IPoint GetPoint()
{
const double Min=-10;
const double Max=10;
Random random = new Random();
double x=Min + (Max - Min) * random.NextDouble();
double y=Min + (Max - Min) * random.NextDouble();
double z=Min + (Max - Min) * random.NextDouble();
IPoint point = ConstructPoint3D(x, y, z);
MakeZAware(point as IGeometry);
return point;
}
private static IPoint ConstructPoint3D(double x, double y, double z)
{
IPoint point=ConstructPoint2D(x, y);
point.Z=z;
return point;
}
private static IPoint ConstructPoint2D(double x, double y)
{
IPoint point = new PointClass();
point.PutCoords(x, y);
return point;
}
private static void MakeZAware(IGeometry geometry)
{
IZAware zAware=geometry as IZAware;
zAware.ZAware = true;
}
public static IVector3D ConstructVector3D(double xComponent, double yComponent, double zComponent)
{
IVector3D vector3D = new Vector3DClass();
vector3D.SetComponents(xComponent, yComponent, zComponent);
return vector3D;
}