Mercurial > hg > nsaunier > traffic-intelligence
view python/tests/prediction.txt @ 372:349eb1e09f45
Cleaned the methods/functions indicating if a point is in a polygon
In general, shapely should be used, especially for lots of points:
from shapely.geometry import Polygon, Point
poly = Polygon(array([[0,0],[0,1],[1,1],[1,0]]))
p = Point(0.5,0.5)
poly.contains(p) -> returns True
poly.contains(Point(-1,-1)) -> returns False
You can convert a moving.Point to a shapely point: p = moving.Point(1,2) p.asShapely() returns the equivalent shapely point
If you have several points to test, use moving.pointsInPolygon(points, polygon) where points are moving.Point and polygon is a shapely polygon.
| author | Nicolas Saunier <nicolas.saunier@polymtl.ca> |
|---|---|
| date | Tue, 16 Jul 2013 17:00:17 -0400 |
| parents | e56c34c1ebac |
| children | e891a41c6c75 |
line wrap: on
line source
>>> import prediction >>> import moving >>> et = prediction.PredictedTrajectoryConstant(moving.Point(0,0), moving.Point(1,0)) >>> et.predictPosition(4) # doctest:+ELLIPSIS (4.0...,0.0...) >>> et.predictPosition(1) # doctest:+ELLIPSIS (1.0...,0.0...) >>> et = prediction.PredictedTrajectoryConstant(moving.Point(0,0), moving.Point(1,0), moving.NormAngle(0.1,0), maxSpeed = 2) >>> et.predictPosition(10) # doctest:+ELLIPSIS (15.5...,0.0...) >>> et.predictPosition(11) # doctest:+ELLIPSIS (17.5...,0.0...) >>> et.predictPosition(12) # doctest:+ELLIPSIS (19.5...,0.0...) >>> import random >>> acceleration = lambda: random.uniform(-0.5,0.5) >>> steering = lambda: random.uniform(-0.1,0.1) >>> et = prediction.PredictedTrajectoryNormalAdaptation(moving.Point(0,0),moving.Point(1,1), acceleration, steering, maxSpeed = 2) >>> p = et.predictPosition(500) >>> from numpy import max >>> max(et.getPredictedSpeeds()) <= 2. True >>> p = moving.Point(3,4) >>> sp = prediction.SafetyPoint(p, 0.1, 0) >>> print(sp) 3 4 0.1 0
