Interface IRay
Provides access to 3D Ray properties and methods. A ray has one endpoint (its origin) and continues infinitely in one direction.
[Guid("0CD38CBA-1C89-11D4-9F5C-00C04F6BDF0D")]
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
public interface IRay : IGeometry
Remarks
A fixed tolerance value is currently used for the three intersection methods: Intersects(), Intersect(), and QueryFirstIntersection().

public IRay CreateRay(IPoint point, IVector3D vector)
{
IRay ray = new RayClass();
//If the input point.Z is NAN (Not A Number = value not set) set the z to 0
if (point.Z.Equals(Double.NaN))
{
point.Z = 0;
}
ray.Origin = point;
ray.Vector = vector;
return ray;
}
Properties
Dimension
esriGeometryDimension Dimension { get; }
Property Value
Envelope
IEnvelope Envelope { get; }
Property Value
GeometryType
esriGeometryType GeometryType { get; }
Property Value
IsEmpty
bool IsEmpty { get; }
Property Value
Origin
The origin point of the ray.
IPoint Origin { get; set; }
Property Value
Remarks

SpatialReference
ISpatialReference SpatialReference { get; set; }
Property Value
Vector
The direction vector of the ray.
IVector3D Vector { get; set; }
Property Value
Remarks

Methods
GeoNormalize()
void GeoNormalize()
GeoNormalizeFromLongitude(double)
void GeoNormalizeFromLongitude(double Longitude)
Parameters
Longitudedouble
GetEnumIntersect(IGeometry)
Not implemented at this release.
IEnumIntersection GetEnumIntersect(IGeometry targetGeometry)
Parameters
targetGeometryIGeometry
Returns
Remarks
This method is currently not implemented.
GetPointAtDistance(double)
Constructs a point at a distance along the ray.
IPoint GetPointAtDistance(double distance)
Parameters
distancedouble
Returns
Intersect(IGeometry, IPointCollection)
Returns a point collection containing all points of intersection, in order along the ray.
void Intersect(IGeometry targetGeometry, IPointCollection intersectionPoints)
Parameters
targetGeometryIGeometryintersectionPointsIPointCollection
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.

public static void QueryPointsOfIntersection()
{
ILine
line =
new
LineClass();
line.FromPoint
= GetPoint();
line.ToPoint =
GetPoint();
IRay
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
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;
}
Intersects(IGeometry)
Indicates if the ray intersects the target geometry.
bool Intersects(IGeometry targetGeometry)
Parameters
targetGeometryIGeometry
Returns
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.

public static void TestIntersection()
{
ILine
line =
new
LineClass();
line.FromPoint
= GetPoint();
line.ToPoint =
GetPoint();
IRay
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
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;
}
Project(ISpatialReference)
void Project(ISpatialReference newReferenceSystem)
Parameters
newReferenceSystemISpatialReference
QueryEnvelope(IEnvelope)
void QueryEnvelope(IEnvelope outEnvelope)
Parameters
outEnvelopeIEnvelope
QueryFirstIntersection(IGeometry, IPoint)
Returns the first point of intersection between the ray and the target geometry. The point is set empty if there is no intersection.
void QueryFirstIntersection(IGeometry targetGeometry, IPoint intersectionPoint)
Parameters
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.

public static void QueryFirstIntersection()
{
ILine
line =
new
LineClass();
line.FromPoint
= GetPoint();
line.ToPoint =
GetPoint();
IRay
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
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;
}
QueryOrigin(IPoint)
Sets a point equal to the ray's origin.
void QueryOrigin(IPoint vectorOrigin)
Parameters
vectorOriginIPoint
Remarks
Note: The output geometry must be co-created prior to the query. The output geometry is not co-created by the method; it is populated. This can be used in performance critical situations. For example, creating the geometry only once outside a loop and use the query method could improve performance.

QueryPointAtDistance(double, IPoint)
Queries a point at a distance along the ray.
void QueryPointAtDistance(double distance, IPoint Point)
Parameters
QueryVector(IVector3D)
Sets a vector equal to a unit vector with the same direction as the ray.
void QueryVector(IVector3D directionVector)
Parameters
directionVectorIVector3D
Remarks

SetEmpty()
void SetEmpty()
SnapToSpatialReference()
void SnapToSpatialReference()