# Towards Moving Objects Behavior Analysis: Region Speed Limit Rate Measure
## 2 Definitions and Methods
It receives a set of trajectories (\(TT\)), a cell (\(r\)), a speed limit (_MaxSpeed_), and the temporal segment (_TempSeg_) associated with the spatiotemporal scenario where the cell \(r\) is located. **CellSpeedLimitRate**(TT, r, MaxSpeed, TempSeg)  
**Input**:  
TT //Array of trajectories  
r //Cell of a spatiotemporal scenario where the speed limit rate will be computed  
MaxSpeed //Speed limit  
TempSeg //Temporal segment of the spatiotemporal scenario where the cell r is located  
**Output**:  
speedLimitRate //Speed limit rate of r  
**DECLARE**  
speedLimitRate = 0;  
maximAlSlowSegmentsDistance = 0; //Total distance of all the maximal slow segments  
maximAlSegmentsDistance = 0; //Total distance of all the maximal segments  
euclideanDist; //Euclidean distance between two CPs  
**BEGIN**  
1. **FOR EACH** trajectory T \(\in\) TT  
2. //Traverse trajectory T  
3. **FOR i = 1 TO** size(T)-1; //size(T) function returns the number of CPs of T  
4. //Checks spatial and temporal inclusion of T[i] and T[i+1] in r  
5. **If**inside((T[i], x, T[i], y), r) **AND T[i],t \(\in\) TempSeg AND**  
6. **inside((T[i+1], x, T[i+1], y), r) **AND T[i+1],t \(\in\) TempSeg THEN**  
7. //Euclidean distance between T[i] and T[i+1]  
8. **euclideanDist= euclideandistance((T[i], x, T[i], y), (T[i+1], x, T[i+1], y))**  
9. **maximalSegmentsDistance += euclideanDist;**  
10. //Checks the speed condition  
11. **IF** (speed(T[i], T[i+1]) \(\leq\) MaxSpeed) **THEN**  
12. **maximalSlowSegmentsDistance += euclideanDist;**  
13. **END IF**  
14. **END IF**  
15. **END FOR**  
16. **END FOR EACH**  
17. **IF** (maximalSegmentsDistance > 0) **THEN**  
18. //Compute speed limit rate of r  
19. **speedLimitRate** = maximalSlowSegmentsDistance / maximalSegmentsDistance;  
20. **END IF;**  
21. **RETURN** speedLimitRate;  
**END CellSpeedLimitRate**  
Basically, the algorithm loops through the array of trajectories \(TT\) (line 1). Next, the CPs of each trajectory \(T\) (line 3) are traversed. For each pair of consecutive CPs, \(T\)[i] and \(T\)[i+1] are verified if both are inside cell \(r\) (spatial inclusion) and belong to the temporal segment _TempSeg_ (temporal inclusion) (lines 5 and 6). If so, the variable _maximalSegmentsDistance_ (line 9) is incremented and then it is verified if the two CPs also meet the speed condition (line 11). If so, the variable _maximalSlowSegmentsDistance_ (line 12) is incremented. Finally, the algorithm computes the _speedLimitRate_ (line 19). Note that each trajectory is traversed only once. Thus, the total number of iterations of the algorithm is equal to the total number of CPs of the trajectories--\(\mid\)TT\(\mid\) (because the last CP of each trajectory is not traversed, see line 3). The inside(\(p\), \(r\)) Boolean function (lines 5 and 6), where \(p\) is a point(\(x\), \(y\)) and \(r\) is a cell (a square of side \(l\)), is defined as follows. Let (\(rx\), \(ry\)) be the coordinate of the bottom-leftcorner of \(r\). The function returns TRUE if \(p\) is inside \(r\) otherwise, it returns FALSE. \(p\) is inside \(r\) if the two following conditions are met:  
* \(x\geq rx\) and \(x\leq rx+l\)
* \(y\geq ry\) and \(y\leq ry+l\)  
The speed(T[i], T[i+1]) function (line 11) is calculated as follows:  
speed(T[i], T[i+1]) = EuclideanDistance((T[i].x, T[i].y), (T[i+1].x, T[i+1].y))/(T[i+1].t - T[i].t).