sim.direction module¶
The module direction provides classes to describe the direction in the
simulation world. It contains an abstract class for extension. To write
your own direction class, your class must extend sim.direction.DIR
abstract class and implement the corresponding abstract methods.
Note
Created by: CH Foh (2021)
List of Classes¶
Dir2D¶
For a flat world, use Dir2D class which describes an angle of a direction. The angle for a North pointing direction is 0 degree. The angle increases as the direction rotates clockwise.
NorthDir¶
It is a constant north pointing direction.
-
class
sim.direction.DIR(azimuth: float = 0, elevation: float = 0)¶ Bases:
abc.ABCThis is an abstract class for direction. All direction classes should extend this class. It may have several abstract methods to be reimplemented.
Methods
clone()Clone a copy of this instance.
Return the azimuth angle.
Return the elevation angle.
is_within(other, range)This function returns a bool describing if the direction of other is within a specific range of its direction.
rotate_to(other)This is a method to set its direction to other.
set_azimuth_given(from_loc, to_loc)Set the direction to the azimuth angle from a point viewing to another point.
-
abstract
__init__(azimuth: float = 0, elevation: float = 0)¶ This is an abstract constructor to be reimplemented. Subclass should call super() to create azimuth and elevation angles.
-
abstract
clone()¶ Clone a copy of this instance.
-
abstract
is_within(other, range: float) → bool¶ This function returns a bool describing if the direction of other is within a specific range of its direction.
- Parameters
- otherAn instance of extended DIR
The other direction to compare with.
- rangefloat
A positive real number specifying the +/- range within itself.
- Returns
- bool
Return whether other is +/- range within itself.
-
abstract
rotate_to(other: sim.direction.Dir2D)¶ This is a method to set its direction to other.
-
abstract
get_azimuth()¶ Return the azimuth angle.
-
abstract
get_elevation()¶ Return the elevation angle.
-
set_azimuth_given(from_loc, to_loc)¶ Set the direction to the azimuth angle from a point viewing to another point.
- Parameters
- from_locAn instance of extended LOC
The viewing location.
- to_locAn instance of extended LOC
The location to view to from from_loc.
-
abstract
-
class
sim.direction.Dir2D(azimuth=0)¶ Bases:
sim.direction.DIRThis is a class which describes an angle of a direction in 2D. The angle for a North pointing direction is 0 degree. The angle increases as the direction rotates clockwise. This class has a constant elevation angle of zero.
Methods
clone()Clone a copy of this instance.
diff(other)This function returns the angle of other from its point of view.
Return the azimuth angle.
Return the elevation angle.
is_within(other, range)This function returns a bool describing if the direction of other is within a specific range of its direction on either side.
rotate(angle)Use this method to rotate its direction clockwise by an angle.
rotate_to(other)This is a method to set its direction to other.
set_azimuth_given(from_loc, to_loc)Set the direction to the azimuth angle from a point viewing to another point.
-
__init__(azimuth=0)¶ This is the constructor.
- Parameters
- azimuthfloat
The azimuth angle. For a North pointing direction, the angle is 0 degree. The angle increases as the direction rotates clockwise.
-
clone()¶ Clone a copy of this instance.
-
get_azimuth()¶ Return the azimuth angle.
-
get_elevation()¶ Return the elevation angle.
-
rotate(angle)¶ Use this method to rotate its direction clockwise by an angle.
-
rotate_to(other: sim.direction.Dir2D)¶ This is a method to set its direction to other.
-
diff(other: sim.direction.Dir2D) → float¶ This function returns the angle of other from its point of view. That is, what is the angle of other if its angle is zero.
-
is_within(other: sim.direction.Dir2D, range: float) → bool¶ This function returns a bool describing if the direction of other is within a specific range of its direction on either side. See description in base class for detail.
-
-
class
sim.direction.NorthDir¶ Bases:
sim.direction.Dir2DThis is a shortcut to create a fixed North pointing direction.
Methods
clone()Clone a copy of this instance.
diff(other)This function returns the angle of other from its point of view.
get_azimuth()Return the azimuth angle.
get_elevation()Return the elevation angle.
is_within(other, range)This function returns a bool describing if the direction of other is within a specific range of its direction on either side.
rotate(angle)Use this method to rotate its direction clockwise by an angle.
rotate_to(other)The method does nothing, since this instance describes a constant direction.
set_azimuth_given(from_loc, to_loc)Set the direction to the azimuth angle from a point viewing to another point.
-
__init__()¶ This is the constructor.
- Parameters
- azimuthfloat
The azimuth angle. For a North pointing direction, the angle is 0 degree. The angle increases as the direction rotates clockwise.
-
clone()¶ Clone a copy of this instance.
-
rotate_to(other)¶ The method does nothing, since this instance describes a constant direction.
-