Mercurial > hg > nsaunier > traffic-intelligence
annotate 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 |
| rev | line source |
|---|---|
|
271
bbd9c09e6869
changed the names to prediction methods and predicted trajectories
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
256
diff
changeset
|
1 >>> import prediction |
|
255
13ec22bec5d4
corrected typos and bugs and added a test
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
2 >>> import moving |
|
13ec22bec5d4
corrected typos and bugs and added a test
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
3 |
|
271
bbd9c09e6869
changed the names to prediction methods and predicted trajectories
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
256
diff
changeset
|
4 >>> et = prediction.PredictedTrajectoryConstant(moving.Point(0,0), moving.Point(1,0)) |
|
255
13ec22bec5d4
corrected typos and bugs and added a test
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
5 >>> et.predictPosition(4) # doctest:+ELLIPSIS |
|
271
bbd9c09e6869
changed the names to prediction methods and predicted trajectories
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
256
diff
changeset
|
6 (4.0...,0.0...) |
|
255
13ec22bec5d4
corrected typos and bugs and added a test
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
7 >>> et.predictPosition(1) # doctest:+ELLIPSIS |
|
271
bbd9c09e6869
changed the names to prediction methods and predicted trajectories
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
256
diff
changeset
|
8 (1.0...,0.0...) |
|
256
dc1faa7287bd
added the normal adaptation class
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
255
diff
changeset
|
9 |
|
271
bbd9c09e6869
changed the names to prediction methods and predicted trajectories
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
256
diff
changeset
|
10 >>> et = prediction.PredictedTrajectoryConstant(moving.Point(0,0), moving.Point(1,0), moving.NormAngle(0.1,0), maxSpeed = 2) |
|
256
dc1faa7287bd
added the normal adaptation class
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
255
diff
changeset
|
11 >>> et.predictPosition(10) # doctest:+ELLIPSIS |
|
271
bbd9c09e6869
changed the names to prediction methods and predicted trajectories
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
256
diff
changeset
|
12 (15.5...,0.0...) |
|
256
dc1faa7287bd
added the normal adaptation class
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
255
diff
changeset
|
13 >>> et.predictPosition(11) # doctest:+ELLIPSIS |
|
271
bbd9c09e6869
changed the names to prediction methods and predicted trajectories
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
256
diff
changeset
|
14 (17.5...,0.0...) |
|
256
dc1faa7287bd
added the normal adaptation class
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
255
diff
changeset
|
15 >>> et.predictPosition(12) # doctest:+ELLIPSIS |
|
271
bbd9c09e6869
changed the names to prediction methods and predicted trajectories
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
256
diff
changeset
|
16 (19.5...,0.0...) |
|
256
dc1faa7287bd
added the normal adaptation class
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
255
diff
changeset
|
17 |
|
dc1faa7287bd
added the normal adaptation class
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
255
diff
changeset
|
18 >>> import random |
|
dc1faa7287bd
added the normal adaptation class
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
255
diff
changeset
|
19 >>> acceleration = lambda: random.uniform(-0.5,0.5) |
|
dc1faa7287bd
added the normal adaptation class
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
255
diff
changeset
|
20 >>> steering = lambda: random.uniform(-0.1,0.1) |
|
271
bbd9c09e6869
changed the names to prediction methods and predicted trajectories
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
256
diff
changeset
|
21 >>> et = prediction.PredictedTrajectoryNormalAdaptation(moving.Point(0,0),moving.Point(1,1), acceleration, steering, maxSpeed = 2) |
|
256
dc1faa7287bd
added the normal adaptation class
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
255
diff
changeset
|
22 >>> p = et.predictPosition(500) |
|
dc1faa7287bd
added the normal adaptation class
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
255
diff
changeset
|
23 >>> from numpy import max |
|
dc1faa7287bd
added the normal adaptation class
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
255
diff
changeset
|
24 >>> max(et.getPredictedSpeeds()) <= 2. |
|
dc1faa7287bd
added the normal adaptation class
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
255
diff
changeset
|
25 True |
|
289
e56c34c1ebac
refactored and commented functions (saving data is now outside of the computation functions)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
271
diff
changeset
|
26 |
|
e56c34c1ebac
refactored and commented functions (saving data is now outside of the computation functions)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
271
diff
changeset
|
27 >>> p = moving.Point(3,4) |
|
e56c34c1ebac
refactored and commented functions (saving data is now outside of the computation functions)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
271
diff
changeset
|
28 >>> sp = prediction.SafetyPoint(p, 0.1, 0) |
|
e56c34c1ebac
refactored and commented functions (saving data is now outside of the computation functions)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
271
diff
changeset
|
29 >>> print(sp) |
|
e56c34c1ebac
refactored and commented functions (saving data is now outside of the computation functions)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
271
diff
changeset
|
30 3 4 0.1 0 |
