The Ray2d class represents a half-bounded line in 2D space (XY plane), defined by a base point and a direction vector.
Autodesk.AutoCAD.Geometry
| Property | Type | Description |
|---|---|---|
BasePoint |
Point2d |
Gets the starting point of the ray |
Direction |
Vector2d |
Gets the direction vector of the ray |
| Method | Return Type | Description |
|---|---|---|
GetClosestPointTo(Point2d) |
Point2d |
Gets closest point on ray |
DistanceTo(Point2d) |
double |
Gets distance from point to ray |
IsOn(Point2d) |
bool |
Checks if point is on ray |
Point2d basePoint = new Point2d(0, 0);
Vector2d direction = new Vector2d(1, 1).GetNormal();
Ray2d ray = new Ray2d(basePoint, direction);
ed.WriteMessage($"\n2D Ray from {ray.BasePoint} in direction {ray.Direction}");Ray2d ray = new Ray2d(new Point2d(0, 0), new Vector2d(1, 0));
Point2d testPoint = new Point2d(10, 5);
Point2d closestPoint = ray.GetClosestPointTo(testPoint);
double distance = ray.DistanceTo(testPoint);
ed.WriteMessage($"\nClosest point: ({closestPoint.X:F2}, {closestPoint.Y:F2})");
ed.WriteMessage($"\nDistance: {distance:F2}");- 2D Performance: Use Ray2d for planar ray casting (faster than 3D)
- Direction: Normalize direction vector
- Half-Bounded: Extends from base point in one direction only
- Ray3d - 3D half-bounded line
- Line2d - Unbounded 2D line
- LineSegment2d - Bounded 2D line segment