This repo contains the original code for my version of the waterworld environment with a detailed guide of the code structure.
In the above image, the clipped_vector
is only clipped along the y
axis, thus the clipped_endpoint
is at (xSensorVector, yClippedVector)
, while the sensor_endpoint
is at (xSensorVector, ySensorVector)
. We can see that the intersection point with the barrier along the sensor
is at
Since the sensor readings for the barrier distance is between
See waterworld_base.Pursuers.get_sensor_barrier_readings
for the implementation details. One place that needs further explantation is
ratios = np.divide(
clipped_vectors,
sensor_vectors,
out=np.ones_like(clipped_vectors),
where=np.abs(sensor_vectors) > 1e-8,
)
The out
argument initializes the output array with all ones, and the where
argument acts like a mask. If (np.abs(sensor_vectors) > 1e-8)[i, j] = True
, the output array at that position would contain the result of clipped_vectors[i, j] / sensor_vectors[i, j]
. If where[i, j] = False
, then the output at that position would contain np.ones_like(clipped_vectors)[i, j]
. This is used to take care of situations when x_sensor_vector = 0
or y_sensor_vector = 0
.
The distance_vec
is computed as
The relative_speed
is computed as
The projection of distance_vec
along a sensor_vector
can be computed as
The projection of relative_speed
along a sensor_vector
can be computed as
Then, a mask is applied over all the sensed values to determine whether the object can be sensed by a sensor or not. The are three conditions for the object to satisfy to be sensed:
- all the sensors are unidirectional, thus,
distance_vec
must be positive to be sensed, i.e.,
- all the sensors have a fixed range, the object must be within the sensor range to be sensed, i.e.,
- the sensor can only sense objects that intersect with the sensor antenae, thus, the length of the dashed green line must be less than the object radius, i.e.,