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


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

IRay.QueryFirstIntersection Method

Returns the first point of intersection between the ray and the target geometry. The point is set empty if there is no intersection.

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

Parameters targetGeometry
targetGeometry is a parameter of type IGeometry intersectionPoint
intersectionPoint is a parameter of type IPoint

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.

If a Ray intersects an Envelope and is located within the bounds of the Envelope, the result of QueryFirstIntersection will be the point closest to the Ray origin along the Ray, located on the exterior of the Envelope at which an intersection takes place.

[C#]

 

        public static void QueryFirstIntersection()

        {

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

               IPoint firstIntersectionPoint=new PointClass();

               ray.QueryFirstIntersection(multiPatchGeometry, firstIntersectionPoint);


              
//firstIntersectionPoint=(5, -2.13, 0.092)

        }

        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