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


IRay.Intersect Method (ArcObjects .NET 10.5 SDK)
ArcObjects Library Reference (Geometry)  

IRay.Intersect Method

Returns a point collection containing all points of intersection, in order along the ray.

[Visual Basic .NET]
Public Sub Intersect ( _
    ByVal targetGeometry As IGeometry, _
    ByVal intersectionPoints As IPointCollection _
)
[C#]
public void Intersect (
    IGeometry targetGeometry,
    IPointCollection intersectionPoints
);
[C++]
HRESULT Intersect(
  IGeometry* targetGeometry,
  IPointCollection* intersectionPoints
);
[C++]

Parameters targetGeometry
targetGeometry is a parameter of type IGeometry intersectionPoints
intersectionPoints is a parameter of type IPointCollection

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 QueryPointsOfIntersection()

        {

               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();
 

               IPointCollection intersectionPointCollection=new MultipointClass();

               ray.Intersect(multiPatchGeometry, intersectionPointCollection);


              
//intersectionPointCollection[0]=(5, -2.13, 0.092)

               //intersectionPointCollection[1]=(1.612, -2.651, 7.012)
        }

        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