Welcome to clayton-rpi-visual’s documentation!

Contents:

A Camera Class This module is responsible for keeping track of camera-related details

class camera.Camera(focal_len, dpi, fov, x_min, x_max, obj_width, focal_point)

Creates a camera with the given specifications

Parameters:
  • focal_len (float) – focal length of the camera.
  • dpi (float) – dots-per-inch of the camera.
  • fov (float) – distance to which the camera can see. field of vision
convert_to_px(value)

Camera specifications are given in millimeters, but need to be converted to pixels in order to work with image values

Parameters:value (float) – value in millimeters to convert to pixels

Note

Possible update: change to convert to/from various measurements used in images and photography

is_within_view(w_vector, dimensions=2, rect=None)

Determines if a given point on an object is within a cone of vision as determined by two points created from the camera’s view.

Parameters:
  • v (u,) – Points from with a cone is created
  • w (Point2d) – Point to determine if is within the view point of ‘u’ and ‘v’
  • dimension (int) – Number of dimensions of the plane; 2 by default
  • rect (array-like) – List of Point3d objects that form a rectangle; None by default. Only necessary if ‘dimensions’ is 3
Returns:

True if ‘w’ is within cone, otherwise False

Return type:

bool

Note

Points for the ‘rect’ variable must be input in the following order Point 1 - x_max, y_min Point 2 - x_min, y_min Point 3 - x_min, y_max Point 4 - x_max, y_max

object_view2d(x_min, x_max, width)

Creates the object’s current cone of view (provides values for vectors u & v). Sets up the u and v vectors for within view

Parameters:
  • x_min (int) – Minimum x value for the object
  • x_max (int) – Maximum x value for the object
  • width (int) – width of the image seen. This will eventually be a class variable

A Grid class This module is responsible for creating a grid for use in conjunction with tactical

class grid.Grid(interval, height, width, start_val=0, cam=None)

Creates a Grid of the given interval based on the camera height, width and a starting value

Parameters:
  • interval (int) – distance between the grid points
  • width (height,) – will be replaced in later implementations from camera input
  • start_val (int) – value at which the grid should start. 0 by default
  • cam (Camera) – camera object on which the grid will be based
build_grid()

Creates the points for the grid

Returns:Point2d objects representing each point on the grid
Return type:array-like
__remove__(value)

Overrides the remove method of the list class for use with the grid class. Will remove the points from the ‘gridpoints’ class member

draw(mode=0)

Uses matplotlib to produce a graphical representation of the grid

Parameters:
  • mode (int) – A ‘mode’ value of 0 will draw only the grid. A ‘mode’ value of 1 will draw the grid + object (cone) view
  • TODO (create mode as an enumerated type.) –

A Two-Dimensional Point/Vector Class

There are surely much better implementations of this sort of thing, for various definitions of ‘better.’ This module is designed to by easily readable and portable, without having to fuss with installation/importing of modules such as numpy that would probably perform better.

class point2d.Point2d(x=0, y=0)

Creates a 2d vector, defaulting to <0,0>.

Parameters:
  • x (float) – x-coordinate (defaults to 0).
  • y (float) – y-coordinate (defaults to 0).
__neg__()

Negates each entry; overrides unary - operator.

Example

>>> a = Point2d(1,-2)
>>> print(-a)
Point2d: <-1.000000, 2.000000>
__add__(term)

Coordinatewise addition; overrides the + operator.

Example

>>> a = Point2d(1,-2)
>>> b = Point2d(3,5)
>>> print(a+b)
Point2d: <4.000000, 3.000000>
__sub__(term)

Coordinatewise subtraction; overrides the - operator.

Example

>>> a = Point2d(1,-2)
>>> b = Point2d(3,5)
>>> print(a-b)
Point2d: <-2.000000, -7.000000>
__mul__(term)

Dot product; overrides the * operator.

Example

>>> a = Point2d(1,-2)
>>> b = Point2d(3,5)
>>> a*b
-7.0
__getitem__(index)

Vector components; indexed starting at 0.

Example

>>> a = Point2d(1,-2)
>>> a[0]
1.0
>>> a[1]
-2.0
scale(scalar)

Get a scaled version of this vector.

Example

>>> a = Point2d(1,-2)
>>> print(a.scale(-2))
Point2d: <-2.000000, 4.000000>
norm()

Get the norm (length) of this vector.

Example

>>> a = Point2d(1,-2)
>>> a.norm()
2.23606797749979
sqnorm()

Get the squared norm (length) of this vector.

Example

>>> a = Point2d(1,-2)
>>> a.sqnorm()
5.0
unit()

Get a unit vector in the same direction as this one.

Note

Be aware of round-off errors; see the example below.

Example

>>> a = Point2d(1,-2)
>>> print(a.unit())
Point2d: <0.447214, -0.894427>
>>> a.unit().norm()
0.9999999999999999
normalize()

Rescale this vector to have length 1.

Note

Be aware of round-off errors; see the example below.

Example

>>> a = Point2d(1,-2)
>>> a.normalize()
>>> print(a)
Point2d: <0.447214, -0.894427>
>>> a.norm()
0.9999999999999999
truncate(maxlength)

Rescale this vector if needed so its length is not too large.

Parameters:maxlength (float) – Upper limit on the length. If the current length exceeds this, the vector will be rescaled.
Returns:True if rescaling was done, False otherwise.
Return type:bool

Example

>>> a = Point2d(1,-2)
>>> a.truncate(1.0)
True
>>> a = Point2d(-1,2)
>>> a.truncate(5.0)
False
>>> print(a)
Point2d: <-1.000000, 2.000000>
>>> a.truncate(1.0)
True
>>> print(a)
Point2d: <-0.447214, 0.894427>
angle()

Get the polar angle of this vector in radians.

Example

>>> a = Point2d(1,-2)
>>> a.angle()
-1.1071487177940904

Notes

This is implemeted using acos. Perhaps atan gives better performance?

__div__(direction)

Length of an orthogonal projection; overrides the / operator.

Parameters:direction (Point2d) – The vector we project onto; not required to be a unit vector.
Returns:The length of the projection vector.
Return type:float

Notes

Returns the scalar q such that self = q*v2 + v3, where v2 is in the span of direction and v2 and v3 are orthogonal. This is algebraically identical to exact division (/).

If you want the result as a vector, use Point2d.proj(direction) instead.

Examples

>>> a = Point2d(2,2)
>>> b = Point2d(3,0)
>>> a/b
2.0
>>> b/a
2.1213203435596424
proj(direction)

Get the orthogonal projection of this vector onto another.

Parameters:direction (Point2d) – The vector we project onto; not required to be a unit vector.
Returns:The unique vector v2 such that self = q*v2 + v3, where v2 is in the span of direction and v2 and v3 are orthogonal.
Return type:Point2d

Example

>>> a = Point2d(2,4)
>>> b = Point2d(3,-2)
>>> print(a.proj(b))
Point2d: <-0.461538, 0.307692>
>>> print(b.proj(a))
Point2d: <-0.200000, -0.400000>

Notes

If you want both v2 and v3, use Point2d.resolve(direction) instead.

resolve(direction)

Orthogonal decomposition of this vector in a given direction.

Parameters:direction (Point2d) – The vector we project onto; not required to be a unit vector.
Returns:(v2,v3) such that self = q*v2 + v3, where v2 is in the span of direction and v2 and v3 are orthogonal.
Return type:(Point2d, Point2d)

Example

>>> a = Point2d(2,2)
>>> b = Point2d(3,0)
>>> print(a.resolve(b)[0])
Point2d: <-0.461538, 0.307692>
>>> print(a.resolve(b)[1])
Point2d: <2.461538, 3.692308>
>>> print(a.resolve(b)[0]+a.resolve(b)[1])
Point2d: <2.000000, 4.000000>
left_normal()

Returns the left-facing normal of this vector

Example

>>> a = Point2d(1, -2)
>>> print a.left_normal()
Point2d: <2.000000, 1.000000>
__setitem__(index, value)

Allows a value to be assigned to each vector components; indexed starting at 0

Example

>>> a = Point2d(1, -2)
>>> print a
Point2d: <1.000000, -2.000000>
>>> a[0] = 3
>>> a[1] = 5
>>> print a
Point2d: <3.000000, 5.000000>

A 3D Point Class This module is a representation of a three-dimensional point class Very much based on the Point2d class

class point3d.Point3d(x=0, y=0, z=0)

Creates a 3d vector, defaulting to <0, 0, 0>

Parameters:
  • x (float) – x-coordinate; 0 by default
  • y (float) – y-coordinate; 0 by default
  • z (float) – z-coordinate; 0 by default
__sub__(term)

Componentwise subtraction; overrides the - operator.

Example

>>> a = Point3d(1, -2, 0)
>>> b = Point3d(3, 5, 0)
>>> print b - a
Point3d: <2.000000, 7.000000, 0.000000>
__mul__(term)

Dot product; overrides the * operator.

Example

>>> a = Point3d(1, -2, 0)
>>> b = Point3d(3, 5, 0)
>>> print a * b
-7
cross(term)

Cross product

Example

>>> a = Point3d(1, -2, 0)
>>> b = Point3d(3, 5, 0)
>>> print a.cross(b)
Point3d: <0.000000, 0.000000, 11.000000>
__getitem__(index)

Vector components; indexed starting at 0. .. rubric:: Example

>>> a = Point3d(1, -2, 0)
>>> a[0]
1
>>> a[1]
-2
>>> a[2]
0
__setitem__(index, value)

Allows a value to be assigned to each vector component; indexed starting at 0.

Example

>>> a = Point3d(1, -2, 0)
>>> print a
Point3d: <1.000000, -2.000000, 0.000000>
>>> a[0] = 3
>>> print a
Point3d: <3.000000, -2.000000, 0.000000>
>>> a[1] = 4
>>> print a
Point3d: <3.000000, 4.000000, 0.000000>
>>> a[2] = 1
>>> print a
Point3d: <3.000000, 4.000000, 1.000000>
left_normal()

Normal vector

Indices and tables