soar.sim.world¶
Soar World and WorldObject classes/subclasses, for simulating and drawing worlds.
-
class
soar.sim.world.Block(p1, p2, thickness=0.002, **options)¶ Bases:
soar.sim.world.PolygonAn arbitrarily thick wall centered on a line.
Useful when infinitely-thin lines are causing issues with collision detection.
Parameters: - p1 – An
(x, y)tuple orsoar.sim.geometry.Pointas the first endpoint of the line segment. - p1 – An
(x, y)tuple orsoar.sim.geometry.Pointas the second endpoint of the line segment. - thickness (float) – The thickness of the block to expand out from the line on which it is centered.
- **options – Tkinter options.
-
borders¶
-
draw(canvas)¶ Draw the object on a canvas.
Parameters: canvas – A Tkinter Canvas or a subclass, typically a soar.gui.canvas.SoarCanvas, on which the object will be drawn.
- p1 – An
-
class
soar.sim.world.Polygon(points, center=None, **options)¶ Bases:
soar.sim.geometry.PointCollection,soar.sim.world.WorldObjectA movable polygon with Tkinter options.
Parameters: - points – A list of
(x, y)tuples orsoar.sim.geometry.Point. - center – An
(x, y)tuple orsoar.sim.geometry.Pointas the pivot or center of the collection. - **options – Tkinter options.
-
borders¶
-
collision(other, eps=1e-08)¶ Determine whether the polygon intersects with another
WorldObject.Parameters:
-
draw(canvas)¶ Draw the object on a canvas.
Parameters: canvas – A Tkinter Canvas or a subclass, typically a soar.gui.canvas.SoarCanvas, on which the object will be drawn.
- points – A list of
-
class
soar.sim.world.Ray(pose, length, eps=1e-08, **options)¶ Bases:
soar.sim.world.WallA ray of a specified length, origin and direction.
Parameters: - pose – An
(x, y, theta)tuple orsoar.sim.geometry.Poseas the origin of the ray. - length (float) – The length of the ray.
- **options – Tkinter options.
- pose – An
-
class
soar.sim.world.Wall(p1, p2, eps=1e-08, **options)¶ Bases:
soar.sim.world.WorldObject,soar.sim.geometry.LineSegmentA straight wall with Tk options and collision detection.
Note that these walls are infinitely thin, so on-edge collision cannot occur.
Parameters: - p1 – An
(x, y)tuple or asoar.sim.geometry.Pointas the first endpoint of the wall. - p1 – An
(x, y)tuple or asoar.sim.geometry.Pointas the second endpoint of the wall. - eps (float) – The epsilon within which to consider a wall vertical or horizontal.
- **options – Tkinter options.
-
collision(other, eps=1e-08)¶ Determine whether two walls intersect.
Parameters: - other – A
Wall, or otherLineSegmentsubclass. - eps (float) – The epsilon within which to consider two parallel lines the same line.
Returns: A list of
(x, y)tuples consisting of the intersection(s), orNoneif the segments do not intersect.- other – A
-
draw(canvas)¶ Draw the object on a canvas.
Parameters: canvas – A Tkinter Canvas or a subclass, typically a soar.gui.canvas.SoarCanvas, on which the object will be drawn.
- p1 – An
-
class
soar.sim.world.World(dimensions, initial_position, objects=None)¶ Bases:
objectA simulated world containing objects that can be simulated stepwise and drawn on a
soar.gui.canvas.SoarCanvas.-
dimensions¶ tuple – An
(x, y)tuple representing the worlds length and height.
-
initial_position¶ An
(x, y, theta)orsoar.sim.geometry.Poserepresenting the robot’s initial position in the world.
-
objects¶ list – A list of (
WorldObject, layer) tuples containing all of the world’s objects.
-
layer_max¶ int – The highest layer currently allocated to an object in the world.
-
canvas¶ An instance of
soar.gui.canvas.SoarCanvas, if the world is being drawn, otherwiseNone.
Parameters: - dimensions (tuple) – An
(x, y)tuple representing the worlds length and height. - initial_position – An
(x, y, theta)orsoar.sim.geometry.Poserepresenting the robot’s initial position in the world. - objects (list) – The initial
WorldObject(s) to add to the world
-
add(obj, layer=None)¶ Add an object to the world, with an optional layer specification.
Parameters: - obj – A
WorldObject(or a subclass instance). - layer (int) – The layer on which the object is to be drawn. Objects are drawn in order from smallest to
largest layer. If this argument is
None, the object’s layer will be set to one higher than the highest layer in the objects list.
- obj – A
-
delete(canvas)¶ Delete the world from a canvas, by deleting each object at a time.
Parameters: canvas – The soar.gui.canvas.SoarCanvasfrom which to delete.
-
draw(canvas)¶ Draw the world on a canvas.
Objects are drawn in order from the lowest to highest layer if their
do_drawattribute is True.Parameters: canvas – The soar.gui.canvas.SoarCanvason which to draw the world. How each object is drawn is up to the object.
-
find_all_collisions(obj, eps=1e-08, condition=None)¶ Finds all the collisions of a
WorldObjectsubclass with objects in the world.Parameters: - obj – A
WorldObjector subclass instance. Objects in the world must know how to collide with it. - eps (float, optional) – An optional epsilon within which to consider a collision to have occurred. What that
means differs between
WorldObjectsubclasses. - condition (optional) – A function to apply to each object in the world that must be
Truein order for it to be considered.
Returns: A list of
(world_obj, p)tuples, whereworld_objis the object that collided andpis thesoar.sim.geometry.Pointat which the collision occurred. If multiple collision points occurred with the same object, each will be listed separately. If no collisions occurred, returnsNone.Return type: list
- obj – A
-
on_step(step_duration)¶ Perform a single step on the world’s objects.
Parameters: step_duration (float) – The duration of the step in seconds.
-
-
class
soar.sim.world.WorldObject(do_draw, do_step, dummy=False, **options)¶ Bases:
objectAn object that can be simulated and drawn in a
soar.sim.world.Worldon asoar.gui.canvas.SoarCanvas.Classes that are designed to work with a World in Soar may either subclass from this class or implement its methods and attributes to be considered valid.
Parameters: - do_draw (bool) – Sets the value of the
do_drawattribute. - do_step (bool) – Sets the value of the
do_stepattribute. - dummy (bool) – Whether the object is a dummy–that is, not intended to be drawn or stepped, but used for some intermediate calcuation (usually collision).
- **options – Tkinter options. This may include ‘tags’, for drawing on a canvas, line thickness, etc.
-
collision(other, eps=1e-08)¶ Determine whether two
WorldObject(s) collide.Objects that subclass
WorldObjectshould implement collision detection for every applicable class from which they inherit.Parameters: - other – A supported
WorldObjectsubclass with which this object could potentially collide. - eps (float, optional) – The epsilon within which to consider a collision to have occurred, different for each subclass.
Returns: A list of
(x, y)tuples consisting of all the collision points withother, orNoneif there weren’t any.Return type: list
- other – A supported
-
delete(canvas)¶ Delete the object from a canvas.
Parameters: canvas – A Tkinter Canvas or a subclass, typically a soar.gui.canvas.SoarCanvas, from which the object will be deleted.
-
draw(canvas)¶ Draw the object on a canvas.
Parameters: canvas – A Tkinter Canvas or a subclass, typically a soar.gui.canvas.SoarCanvas, on which the object will be drawn.
-
on_step(step_duration)¶ Simulate the object for a step of a specified duration.
Parameters: step_duration – The duration of the step, in seconds.
- do_draw (bool) – Sets the value of the