2D Homogeneous coordinates with transformations
-
class homcoord.Pt(*args)[source]
Bases: object
Represents a homogeneous coordinate in 2-space.
- Exports:
- Pt(*coords):
- [ coords is a 2-sequence or a 1-sequence containing a
- 2-sequence ->
- return a new Pt instance representing those two
values as x and y, respectively
- coords is a 1-sequence containing a 3-sequence ->
- return a new Pt instance representing those values
as x, y, and w, respectively ]
- .xy:
- [ return a 2-tuple with the homogenized x and y values ]
.x: [ return the homogenized x coordinate ]
.y: [ return the homogenized y coordinate ]
.dist(other):
- [ other is a Pt instance ->
- return the distance between self and other ]
- .bearing(p):
- [ p is a Pt instance ->
- return the Cartesian angle in radians from self to p ]
- .radial(d, bearing):
- [ (d is a distance) and (bearing is an angle in radians) ->
- return the location at that distance and bearing as
a Pt instance ]
- .toPolar():
- [ return self in polar coordinates as a Polar instance ]
.__str__(): [ return self as a string ]
.__add__(self, other):
- [ other is a Pt instance ->
- return a new Pt instance whose coordinates are the
sum of self’s and other’s ]
- .__sub__(self, other):
- [ other is a Pt instance ->
- return a new Pt instance whose coordinates are the
self’s minus other’s ]
- .__cmp__(self, other):
- [ if self and other are the same point ->
return 0
else -> return a nonzero value ]
- State/Invariants:
- .v [ a numpy 3-element vector [x, y, W] ]
Constructor.
-
__init__(*args)[source]
Constructor.
-
xy[source]
Return (x,y)
-
x[source]
Return the abscissa.
-
y[source]
Return the ordinate.
-
apply(f)[source]
Returns: | Pt obtained by appying function f to x and y |
-
dist(other)[source]
Return the distance between self and other.
-
bearing(p)[source]
What is the bearing angle from self to p?
-
radial(d, bearing)[source]
Return the point at a given distance and bearing.
-
toPolar()[source]
Convert to polar coordinates.
-
__str__()[source]
Return a string representation of self.
-
__repr__()[source]
-
__add__(other)[source]
Add two points.
-
__sub__(other)[source]
Subtract two points.
-
__mul__(scale)[source]
Multiply by scalar.
-
__div__(scale)[source]
Multiply by scalar.
-
__cmp__(other)[source]
Compare two points.
-
__weakref__
list of weak references to the object (if defined)
-
class homcoord.Xform(m)[source]
Bases: object
Represents an arbitrary homogeneous coordinate transform.
- Exports:
- Xform(m):
- [ m is a 3x3 transform matrix as a array, or
a sequence that array() will accept as a 3x3
array ->
return a new Xform instance representing that
transform ]
- .apply(p):
- [ p is a Pt instance ->
- return a new Pt instance representing p transformed
by self ]
- .invert(p):
- [ p is a Pt instance ->
- return a new Pt instance pp such that
self.apply(pp) == p ]
- .inverse():
- [ return the inverse of self as an Xform instance ]
- .compose(t):
- [ t is an Xform instance ->
- return a new Xform representing the composition of
self followed by t ]
- .offset():
- [ return the net offset that self will shift the origin,
- as a Pt instance ]
- .angle():
- [ return the net angle that self will rotate the unit
- vector from (0,0) to (1,1) ]
- .mag():
- [ return the net magnification that self will apply to the
- unit vector ]
- .__str__(self):
- [ return a string representation of self ]
- State/Invariants:
- self._m:
- [ a 3x3 array representing the argument passed
- to the constructor ]
- self._mInverse:
- [ the inverse of self._m or None ]
- self.__offset:
- [ the net translation of self or None ]
- self.__angle:
- [ the net rotation of self or None ]
- self._mag:
- [ the net uniform scaling of self or None ]
ORIGIN: [ the origin as a Pt instance ]
UNIT: [ a point 1.0 along the line x=y ]
Constructor.
-
ORIGIN = (0, 0)
-
UNIT = (0.7071, 0.7071)
-
__init__(m)[source]
Constructor.
-
apply(p)[source]
Transform a point.
-
__call__(p)[source]
-
invert(p)[source]
Return p transformed by the inverse of self, as a Pt.
-
inverse()[source]
Return the inverse transform as an Xform.
-
__str__()[source]
Display self as a string
-
compose(t2)[source]
Return the composition of two transforms.
-
__mul__(other)[source]
Implement ‘*’
-
offset()[source]
-
angle(angle=0.7853981633974483)[source]
Parameters: | angle – angle in radians of a unit vector starting at origin |
Returns: | float bearing in radians of the transformed vector |
-
mag()[source]
Return the net (uniform) scaling of this transform.
-
__weakref__
list of weak references to the object (if defined)
-
homcoord.Xlate(*p)[source]
Create a translation transform.
-
homcoord.Xscale(*p)[source]
Create a scaling transform.
-
homcoord.Xrotate(theta)[source]
Create a rotation transform.
-
homcoord.Xrotaround(p, theta)[source]
Rotation of theta radians around point p.
-
class homcoord.Polar(*p)[source]
Bases: object
Represents a point in polar coordinates.
- Exports:
- Polar(r, theta):
- [ r and theta are numbers ->
- return a new Polar instance representing radius r
and angle theta ]
.r, .theta: [ as passed to constructor ]
.toCartesian():
[ return self in Cartesian coordinates as a Pt instance ]
- .__str__():
- [ return self as a string “(r, theta)” ]
Constructor
-
__init__(*p)[source]
Constructor
-
toCartesian()[source]
Return self in rectangular coordinates as a Pt instance.
-
__str__()[source]
Return self as a string.
-
__weakref__
list of weak references to the object (if defined)
-
class homcoord.Line(a, b, c)[source]
Bases: object
Represents a geometric line.
- Exports:
- Line(a, b, c):
- [ a, b, and c are floats ->
- return a Line instance representing ax+by+c=0 ]
.a, .b, .c: [ as passed to constructor, read-only ]
.__str__(self): [ return self as a string ]
.intersect(other):
- [ other is a Line instance ->
- if self and other intersect ->
- return the intersection as a Pt
else -> raise ValueError ]
- Line.twoPoint(p1, p2): # Static method
- [ p1 and p2 are Pt instances ->
- if p1 and p2 are distinct ->
- return a Line instance representing the line that
intersects p1 and p2
else -> raise ValueError ]
- Line.pointBearing(p, bears): # Static method
- [ (p is a Pt instance) and
- (bears is a Cartesian bearing in radians) ->
- return the line through p at bearing (bears) ]
Constructor.
-
__init__(a, b, c)[source]
Constructor.
-
__str__()[source]
Return a string representing self.
-
intersect(other)[source]
Where do lines self and other intersect?
-
static twoPoint(p1, p2)[source]
Find the equation of a line between two points.
-
static pointBearing(p, bears)[source]
Line through p at angle (bears).
-
__weakref__
list of weak references to the object (if defined)
-
homcoord.argPair(*p)[source]
Process a pair of values passed in various ways.
- [ if len(p) is 2 ->
return (p[0], p[1])
- else if p is a single non-iterable ->
- return (p[0], p[0])
- else if p is an iterable with two values ->
- return (p[0][0], p[0][1])
- else if p is an iterable with one value ->
- return (p[0][0], p[0][0])
-
homcoord.normAngle(theta)[source]
Normalize an angle in radians to [0, 2*pi)