soar.sim.geometry¶
Geometry classes, for manipulating points, collections of points, lines, and normalizing angles.
-
class
soar.sim.geometry.
Line
(p1, p2, eps=1e-08, normalize=False)¶ Bases:
object
A line in the
(x, y)
plane defined by two points on the line.Parameters: - p1 – An
(x, y)
tuple orPoint
as one of the points on the line. - p2 – An
(x, y)
tuple orPoint
as another point on the line. - eps (float, optional) – The epsilon within which to consider a line horizontal or vertical, for precision purposes.
- normalize (bool, optional) – If
True
, normalize the internal vector representation to be a unit vector.
-
distance_from_line
(p)¶ Determine the (signed) distance of a point from the line.
Parameters: p – An (x, y)
tuple orPoint
to measure distance from.Returns: The signed distance from the line. Return type: float
-
has_point
(p, eps=1e-08)¶ Determine whether a point lies on the line.
Parameters: - p – The
(x, y)
tuple orPoint
to check. - eps (float, optional) – The distance to tolerate before a point is considered not to be on the line.
Returns: True
if the point is on the line,False
otherwise.Return type: bool
- p – The
-
intersection
(other, eps=1e-08)¶ Determine whether two lines intersect.
Parameters: - other – The
Line
to find the intersection with. - eps (float, optional) – The smallest absolute difference to tolerate before the lines are considered to be converging.
Returns: The
Point
of intersection, orNone
if the lines are parallel (based on epsilon).- other – The
- p1 – An
-
class
soar.sim.geometry.
LineSegment
(p1, p2, eps=1e-08)¶ Bases:
soar.sim.geometry.Line
A line segment in the
(x, y)
plane defined by two endpoints.Parameters: -
has_intersect
(other)¶ Determine whether one segment intersects with another.
Parameters: other – Another LineSegment
.Returns: True
if the segments have an intersection,False
otherwise.Return type: bool
-
has_point
(p, eps=1e-08)¶ Determine whether a point lies on the line segment.
Parameters: - p – The
(x, y)
tuple orPoint
to check. - eps (float, optional) – The distance to tolerate before a point is considered not to be on the line segment.
Returns: True
if the point is on the line segment,False
otherwise.Return type: bool
- p – The
-
intersection
(other, eps=1e-08)¶ Find the intersection(s) between two line segments, or this line segment and a
Line
.Parameters: - other – The other
LineSegment
to find intersections with. - eps (float, optional) – The epsilon or tolerance to pass to the
Line
intersection andhas_point
checks.
Returns: Either a list of
Point
(s) representing all of the intersections, orNone
, if there weren’t any. Also returnsNone
if the segment and aLine
are exactly parallel.- other – The other
-
-
class
soar.sim.geometry.
Point
(x, y)¶ Bases:
object
Represents a point in the x, y plane.
Points can be interpreted and treated as x, y tuples in most cases.
-
x
¶ float – The x coordinate of the point.
-
y
¶ float – The y coordinate of the point.
Parameters: - x (float) – The x coordinate of the point.
- y (float) – The y coordinate of the point.
-
add
(other)¶ Vector addition; adds two points.
Parameters: other – An (x, y)
tuple or an instance ofPoint
.Returns: The Point
that is the sum of this point and the argument.
-
angle_to
(other)¶ Return the angle between two points.
Parameters: other – An (x, y)
tuple or an instance ofPoint
.Returns: Angle in radians of the vector from self to other. Return type: float
-
distance
(other)¶ Calculate the distance between two points.
Parameters: other – An (x, y)
tuple or an instance ofPoint
.Returns: The Euclidean distance between the points. Return type: float
-
is_near
(other, eps)¶ Determine whether the distance between two points is within a certain value.
Parameters: - other – An
(x, y)
tuple or an instance ofPoint
. - eps (float) – The epilson within which to consider the points near one another.
Returns: True
if the points are withingeps
of each other,False
otherwise.Return type: bool
- other – An
-
magnitude
()¶ The magnitude of this point interpreted as a vector.
Returns: The magnitude of the vector from the origin to this point. Return type: float
-
midpoint
(other)¶ Return a new
Point
that is the midpoint of self and other.Parameters: other – An (x, y)
tuple or an instance ofPoint
.Returns: A Point
that is the midpoint of self and other.
-
rotate
(other, theta)¶ Rotate about other by theta radians (positive values are counterclockwise).
Parameters: - other – An
(x, y)
tuple or an instance ofPoint
. - theta (float) – The number of radians to rotate counterclockwise.
Returns: The rotated
Point
.- other – An
-
scale
(value, other=(0, 0))¶ Scale the vector from other to self by value, and return the endpoint of that vector.
Parameters: - value (float) – The value to scale by.
- other – An
(x, y)
tuple or aPoint
as the origin to scale from.
Returns: The endpoint of the scaled vector, as a
Point
.
-
sub
(other)¶ Vector subtraction; subtracts subtracts two points.
Parameters: other – An (x, y)
tuple or an instance ofPoint
.Returns: The Point
that is the difference of this point and the argument.
-
xy_tuple
()¶ Returns: An
(x, y)
tuple representing the point.
-
-
class
soar.sim.geometry.
PointCollection
(points, center=None)¶ Bases:
object
A movable collection of points.
Can be iterated over like a list of
Point
. UnlikePoint
, PointCollections are mutable–that is, rotating them, translating them, etc. changes the internal point list.Parameters: -
recenter
(new_center)¶ Re-center the collection.
Parameters: new_center – An (x, y)
tuple orPoint
that will be the collection’s new center.
-
rotate
(pivot, theta)¶ Rotate about other by theta radians (positive values are counterclockwise).
Parameters: - pivot – An
(x, y)
tuple or aPoint
. - theta (float) – The number of radians to rotate counterclockwise.
- pivot – An
-
-
class
soar.sim.geometry.
Pose
(x, y, t)¶ Bases:
soar.sim.geometry.Point
A point facing a direction in the xy plane.
Poses can be interpreted and treated as
(x, y, theta)
tuples in most cases.Parameters: - x – The x coordinate of the pose.
- y – The y coordinate of the pose.
- t – The angle between the direction the pose is facing and the positive x axis, in radians.
-
copy
()¶ Returns a copy of the Pose.
-
is_near
(other, dist_eps, angle_eps)¶ Determine whether two poses are close.
Parameters: - other – An
(x, y, t)
tuple orPose
. - dist_eps (float) – The distance epilson within which to consider the poses close.
- angle_eps (float) – The angle episilon within which to consider the poses close.
Returns: True
if the distance between the point portions is withindist_eps
, and the normalized difference between the angle portions is withinangle_eps
.Return type: bool
- other – An
-
point
()¶ Strips the angle component of the pose and returns a point at the same position.
Returns: The (x, y)
portion of the pose, as aPoint
.
-
rotate
(pivot, theta)¶ Rotate the point portion of the pose about a pivot. Leaves the theta portion unchanged.
Parameters:
-
transform
(other)¶ Return a new pose that has been transformed (translated and turned).
Parameters: other – A Pose
or 3-tuple-like object, by which to translate and turn.Returns: A new Pose
equivalent to translatingself
by(other[0], other[1])
and rotating byother[2]
.
-
xyt_tuple
()¶ Returns: An
(x, y, t)
tuple representing the pose.
-
soar.sim.geometry.
ccw
(p1, p2, p3)¶ Determine whether the turn formed by points p1, p2, and p3 is counterclockwise.
Parameters:
-
soar.sim.geometry.
clip
(value, m1, m2)¶ Clip a value between two bounds.
Parameters: - value (float) – The value to clip.
- m1 (float) – The first bound.
- m2 (float) – The second bound.
Returns: A clipped value guaranteed to be between the min and max of the bounds.
Return type: float
-
soar.sim.geometry.
normalize_angle_180
(theta)¶ Normalize an angle in radians to be within
-pi
andpi
.Parameters: theta (float) – The angle to normalize, in radians. Returns: The normalized angle. Return type: float
-
soar.sim.geometry.
normalize_angle_360
(theta)¶ Normalize an angle in radians to be within
0
and2*pi
.Parameters: theta (float) – The angle to normalize, in radians. Returns: The normalized angle. Return type: float