This document is archived and information here might be outdated.  Recommended version.


IRay.Intersects Method (ArcObjects .NET 10.8 SDK)
ArcObjects Help for .NET developers > ArcObjects Help for .NET developers > ArcObjects namespaces > Geometry > ESRI.ArcGIS.Geometry > Interfaces > IR > IRay Interface > IRay.Intersects Method
ArcGIS Developer Help

IRay.Intersects Method

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
);
[C++]
Parameters
targetGeometry 

targetGeometry is a parameter of type IGeometry*

Product Availability

Available with ArcGIS Engine, ArcGIS Desktop, and ArcGIS Server.

Description

Implemented for Points, Multipoints, Polylines, Polygons, Envelopes, and Multipatches.

Remarks

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.

[C#]

 

        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;

        }

See Also

IRay Interface