Mercurial > hg > nsaunier > traffic-intelligence
diff trafficintelligence/moving.py @ 1282:106365257da9
reorganization of moving.py and adding documentation tests
| author | Nicolas Saunier <nicolas.saunier@polymtl.ca> |
|---|---|
| date | Tue, 09 Jul 2024 17:44:51 -0400 |
| parents | 8915747a4fc8 |
| children | 77a310e29233 |
line wrap: on
line diff
--- a/trafficintelligence/moving.py Mon Jul 08 16:42:30 2024 -0400 +++ b/trafficintelligence/moving.py Tue Jul 09 17:44:51 2024 -0400 @@ -1575,6 +1575,9 @@ obj = MovingObject(self.num, intersection, self.positions.subTrajectoryInInterval(trajectoryInterval), self.geometry, self.userType, self.nObjects) if self.velocities is not None: obj.velocities = self.velocities.subTrajectoryInInterval(trajectoryInterval) + if hasattr(self, 'curvilinearPositions'): + obj.curvilinearPositions = self.curvilinearPositions.subTrajectoryInInterval(trajectoryInterval) + return obj else: print('The object does not exist at {}'.format(inter)) @@ -1872,7 +1875,8 @@ if self.hasFeatures(): for f in self.getFeatures(): f.setStationary() - + + # Plotting functions def plot(self, options = '', withOrigin = False, timeStep = 1, withFeatures = False, withOutline = False, withIds = False, **kwargs): if withIds: objNum = self.getNum() @@ -2092,6 +2096,19 @@ (returns an actual value, otherwise munkres does not terminate)''' return Point.distanceNorm2(self.getPositionAtInstant(instant), obj.getPositionAtInstant(instant)) + @staticmethod + def collisionCourseDotProduct(movingObject1, movingObject2, instant): + 'A positive result indicates that the road users are getting closer' + deltap = movingObject1.getPositionAtInstant(instant)-movingObject2.getPositionAtInstant(instant) + deltav = movingObject2.getVelocityAtInstant(instant)-movingObject1.getVelocityAtInstant(instant) + return Point.dot(deltap, deltav) + + @staticmethod + def collisionCourseCosine(movingObject1, movingObject2, instant): + 'A positive result indicates that the road users are getting closer' + return Point.cosine(movingObject1.getPositionAtInstant(instant)-movingObject2.getPositionAtInstant(instant), #deltap + movingObject2.getVelocityAtInstant(instant)-movingObject1.getVelocityAtInstant(instant)) #deltav + ### # User Type Classification ### @@ -2236,19 +2253,6 @@ # what to do: threshold for most common type? self.setUserType() return possibleUserTypes - @staticmethod - def collisionCourseDotProduct(movingObject1, movingObject2, instant): - 'A positive result indicates that the road users are getting closer' - deltap = movingObject1.getPositionAtInstant(instant)-movingObject2.getPositionAtInstant(instant) - deltav = movingObject2.getVelocityAtInstant(instant)-movingObject1.getVelocityAtInstant(instant) - return Point.dot(deltap, deltav) - - @staticmethod - def collisionCourseCosine(movingObject1, movingObject2, instant): - 'A positive result indicates that the road users are getting closer' - return Point.cosine(movingObject1.getPositionAtInstant(instant)-movingObject2.getPositionAtInstant(instant), #deltap - movingObject2.getVelocityAtInstant(instant)-movingObject1.getVelocityAtInstant(instant)) #deltav - class Prototype(object): 'Class for a prototype'
