Main Content

raycast

Compute cell indices along a ray

Description

[endpoints,midpoints] = raycast(map,pose,range,angle) returns cell indices of the specified map for all cells traversed by a ray originating from the specified pose at the specified angle and range values. endpoints contains all indices touched by the end of the ray, with all other points included in midpoints.

[endpoints,midpoints] = raycast(map,p1,p2) returns the cell indices of the line segment between the two specified points.

Input Arguments

collapse all

Map representation, specified as a binaryOccupancyMap object. This object represents the environment of the robot. The object contains a matrix grid with binary values indicating obstacles as true (1) and free locations as false (0).

Position and orientation of sensor, specified as an [x y theta] vector. The sensor pose is an x and y position with angular orientation theta (in radians) measured from the x-axis.

Range of ray, specified as a scalar in meters.

Angle of ray, specified as a scalar in radians. The angle value is for the corresponding range.

Starting point of ray, specified as an [x y] two-element vector. Points are defined with respect to the world-frame.

Endpoint of ray, specified as an [x y] two-element vector. Points are defined with respect to the world-frame.

Output Arguments

collapse all

Endpoint indices, returned as an n-by-2 matrix of [i j] pairs, where n is the number of grid indices. The endpoints are where the range value hits at the specified angle. Multiple indices are returned when the endpoint lies on the boundary of multiple cells.

Midpoint indices, returned as an n-by-2 matrix of [i j] pairs, where n is the number of grid indices. This argument includes all grid indices the ray intersects, excluding the endpoint.

Extended Capabilities

C/C++ Code Generation
Generate C and C++ code using MATLAB® Coder™.

See Also

| | (Navigation Toolbox)

Introduced in R2019b