a given rectangular region in space (which we refer to as a query
box). You are given a trajectory and a query box. The trajectory is in
the same format as the previous problem. You can assume that the
observations in the trajectory are ordered by increasing time values.
The query box is given as a tuple that contains two tuples, i.e.,
((x1,y1),(x2,y2)), where the Frst tuple corresponds to the lower-left
corner of the rectangular region, and the second tuple corresponds
to the upper-right corner of the rectangular region.
You can assume that if a trajectory observation falls on the
boundary of the box, it is considered as being inside the box. ±or
example, the observation (1,1,0) is considered to be inside the box
((1,1),(2,2)). Note that in the special case where the trajectory starts
within the query box, then that also counts as an instance of
entering the box.
±or example, for a trajectory containing Fve observations [(1,1,0),
(2,2,1),(3,3,2),(2,2,3),(1,1,4)], it enters the query box ((1.5,1.5),
(2.5,2.5)) twice. ±or the same trajectory [(1,1,0),(2,2,1),(3,3,2),
(2,2,3),(1,1,4)] but a di²erent query box ((0.5,0.5),(1.5,1.5)), it also
enters the query box twice.
Write a function visits(tr, b) that takes a list argument tr
corresponding to a trajectory, and a tuple b corresponding to a
rectangular query box, and returns an int corresponding to the
number of times the trajectory enters the box. You can assume that
the list argument tr contains at least one observation.
Example calls to the function are:
>>>
print(visits([(1,1,0),(2,2,1),(3,3,2),(2,2,3),(1,1,4)],
((1.5,1.5),
(2.5,2.5))))
2
>>>
print(visits([(1,1,0),(2,2,1),(3,3,2),(2,2,3),(1,1,4)],
((1.5,1.5),
(1.6,1.6))))
0
>>> print(visits([(1,1,0),(2,2,1),(3,3,2),(2,2,3),(1,1,4)], ((0,0),(3,3))))
1
>>> print(visits([(1,3,2),(3,3,3),(3,1,4)], ((0,0),(2,2))))
0
The next trajectory analysis function that you will implement
compares two trajectories to see whether two objects are moving
together. We can do this by comparing observations that occur at
the same time in each trajectory, and checking if their distance is
less than or equal to a given threshold. If so, we consider those
observations to be close. The aim is to Fnd the maximum number of