Cast a Lidar Fan
Implement lidar_scan(origin, angles, obstacles, max_range). origin is [x, y], angles are ray headings in radians (direction ), and obstacles is an (N,3) array of rows [cx,cy,R]. Return one distance per angle.
Examples
Straight at a circle: the reading is the near surface, 4 not 5
- Input
- lidar_scan([0, 0], [0], [[5, 0, 1]], 10)
- Output
- [4]
Nothing that way: the ray reads max_range
- Input
- lidar_scan([0, 0], [1.5707963267948966], [[5, 0, 1]], 10)
- Output
- [10]
A four-ray fan around one obstacle
- Input
- lidar_scan([0, 0], [0, 1.5707963267948966, 3.141592653589793, 4.71238898038469], [[5, 0, 1]], 10)
- Output
- [4, 10, 10, 10]
Hints
Hint 1
Use a matrix product rather than nested loops, and check which operand transposes.
Hint 2
A common slip here: returned the distance to the circle centre instead of to its surface.
Requirements
origin: [x, y] start of every rayangles: (K,) ray headings in radiansobstacles: (N, 3) rows [cx, cy, radius]max_range: reading returned when a ray hits nothingReturn (K,) distances, each in (0, max_range]
Constraints
Allowed library: NumPy only
Time limit: 200 ms, Memory: 64 MB
Try similar problems(4)
Reinforcement Learning: Rewards, Senses and PPO · ~18 min
Reinforcement Learning: Rewards, Senses and PPO · ~16 min
Reinforcement Learning: Rewards, Senses and PPO · ~18 min
Reinforcement Learning: Rewards, Senses and PPO · ~14 min
import numpy as np
def lidar_scan(origin, angles, obstacles, max_range):
"""
Distance to the nearest circular obstacle along each ray.
Args:
origin: [x, y] start of every ray
angles: (K,) ray headings in radians
obstacles: (N, 3) rows [cx, cy, radius]
max_range: reading returned when a ray hits nothing
Returns:
(K,) distances, each in (0, max_range]
"""
# YOUR CODE HERE
pass