← 返回 tesla 的题目列表Trajectory Waypoint Distance Queries
类型:qbank
Given a 2-D coordinate sequence and a list of travel distances in miles, determine for each distance whether any coordinate point lies within a threshold of the current traveled position.
Requirements
Input: a coordinate sequence where each point is [x_i, y_i].
Input: a list of travel distances, in miles.
Start from the first coordinate and walk through the route according to each requested distance.
For each distance value, determine whether any coordinate point is within a given threshold, such as 1.5 miles, of the current position.
Output the nearest point's index when one exists; otherwise output None.
Notes
The body of the prompt is thin on exact route interpolation rules. Clarify whether movement follows polyline distance along the coordinate sequence or jumps between discrete waypoint samples.
A robust implementation precomputes cumulative segment distances, uses binary search to locate the segment containing each requested travel distance, interpolates the current position, then scans or indexes nearby waypoints.
If distances can exceed the route length, define whether to clamp to the final waypoint, wrap, or return None.
For larger inputs, discuss spatial indexing or a window over nearby cumulative distances instead of scanning every point for every query.
Preparation
Code the cumulative-distance array and binary-search segment lookup, then test exact waypoint hits, mid-segment interpolation, zero-length segments, and distance beyond the last segment.
Add a simple nearest-waypoint scan first; then explain when a KD-tree, grid index, or cumulative-distance window is worth the added complexity.
Prepare one clarification script covering units, coordinate system, threshold metric, tie-breaking, and whether the starting coordinate itself can be returned.