Use python language to answer the three following questions: The aim of this exercise is to implement a function for finding when the trajectory of...
This question has been answered
Question

there are 3 practical questions for python programming language which

are not difficult,i hope someone can help me with that.

1 Attachment
Use python language to answer the three following questions: 1. The aim of this exercise is to implement a function for Fnding when the trajectory of an object is closest to a given point. A point is given by a tuple as a pair of (x,y) coordinates. A trajectory of an object is given by a list of tuples, where each tuple (x,y,t) corresponds to the observed position of the object at a particular time t. Your goal is to write a function that returns the time when the object was observed to be closest to the given point. ±or example, consider the trajectory [(1,1,1),(2,2,2),(3,1.5,3), (1,1,4)], which contains four observations of the position of an object at times t=1, t=2, t=3 and t=4. If we compare this trajectory to the point (3,2), then the closest observation in the trajectory occurs at time t=3. Write a function closestTime(tr, pt) that takes a list argument tr that corresponds to the trajectory of an object, and a tuple argument pt that corresponds to a test point, and returns the int value of the time of the earliest observation in tr that is closest to the test point pt. Note that if two or more observations are closest to the test point (i.e., they are equally close to the test point, and closer than any other observations), then you should return the time of the earliest such observation. You can assume that the given trajectory contains at least one observation, and that the x and y coordinates in the observation are ²oat values, and the time t of the observation is a non-negative int. You can also assume that the x and y coordinates of the test point are ²oat values. You can assume that the observations in the trajectory are ordered by increasing time values. You should calculate the distance between an observation and the test point using the Euclidean distance between two points (x1,y1) and (x2,y2): d(x1,y1,x2,y2)=(x1 x2)2+(y1 y2)2 −−−−−−−−−−−−−−−−−− Example calls to the function are: >>> print(closestTime([(0,0,0),(1,1,1),(2,2,2),(1,1,3)], (2,2))) 2 >>> print(closestTime([(0,0,0),(1,1,1),(2,2,2),(1,1,3)], (1.2,1.1))) 1 >>> print(closestTime([(0,0,2),(1,1,3),(2,2,4),(1,1,5)], (-2,-2))) 2 >>> print(closestTime([(0,0,0)], (-2,-2))) 0 2. Your aim is to count the number of times a given trajectory enters
Background image of page 1
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
Background image of page 2

End of preview

Answered by Expert Tutors

sum dolor sit

, ultrices ac magna. Fusce dui lectus, congue vel laoreet ac, dictum vitae odio. Donec aliquet. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam lacinia pulvinar tortor nec facilisis. Pellentesque dapibus efficitur laoreet. Nam risus ante, dapibus a molestie consequat, ultrices ac magna. Fusce dui lectu
3 Attachments
trajectory.py
py
trajectory2.py
py
trajectory3.py
py
The student who asked this rated it

"thx man"

Get unstuck

435,535 students got unstuck by Course
Hero in the last week

step by step solutions

Our Expert Tutors provide step by step solutions to help you excel in your courses