1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105
|
.. include:: header.rst
.. _Point:
================
Point
================
*Point* represents a point in the plane, defined by its x and y coordinates.
============================ ============================================
**Attribute / Method** **Description**
============================ ============================================
:meth:`Point.distance_to` calculate distance to point or rect
:meth:`Point.norm` the Euclidean norm
:meth:`Point.transform` transform point with a matrix
:attr:`Point.abs_unit` same as unit, but positive coordinates
:attr:`Point.unit` point coordinates divided by *abs(point)*
:attr:`Point.x` the X-coordinate
:attr:`Point.y` the Y-coordinate
============================ ============================================
**Class API**
.. class:: Point
.. method:: __init__(self)
.. method:: __init__(self, x, y)
.. method:: __init__(self, point)
.. method:: __init__(self, sequence)
Overloaded constructors.
Without parameters, *Point(0, 0)* will be created.
With another point specified, a **new copy** will be created, "sequence" is a Python sequence of 2 numbers (see :ref:`SequenceTypes`).
:arg float x: x coordinate of the point
:arg float y: y coordinate of the point
.. method:: distance_to(x [, unit])
Calculate the distance to *x*, which may be :data:`point_like` or :data:`rect_like`. The distance is given in units of either pixels (default), inches, centimeters or millimeters.
:arg point_like,rect_like x: to which to compute the distance.
:arg str unit: the unit to be measured in. One of "px", "in", "cm", "mm".
:rtype: float
:returns: the distance to *x*. If this is :data:`rect_like`, then the distance
* is the length of the shortest line connecting to one of the rectangle sides
* is calculated to the **finite version** of it
* is zero if it **contains** the point
.. method:: norm()
* New in version 1.16.0
Return the Euclidean norm (the length) of the point as a vector. Equals result of function *abs()*.
.. method:: transform(m)
Apply a matrix to the point and replace it with the result.
:arg matrix_like m: The matrix to be applied.
:rtype: :ref:`Point`
.. attribute:: unit
Result of dividing each coordinate by *norm(point)*, the distance of the point to (0,0). This is a vector of length 1 pointing in the same direction as the point does. Its x, resp. y values are equal to the cosine, resp. sine of the angle this vector (and the point itself) has with the x axis.
.. image:: images/img-point-unit.*
:type: :ref:`Point`
.. attribute:: abs_unit
Same as :attr:`unit` above, replacing the coordinates with their absolute values.
:type: :ref:`Point`
.. attribute:: x
The x coordinate
:type: float
.. attribute:: y
The y coordinate
:type: float
.. note::
* This class adheres to the Python sequence protocol, so components can be accessed via their index, too. Also refer to :ref:`SequenceTypes`.
* Rectangles can be used with arithmetic operators -- see chapter :ref:`Algebra`.
.. include:: footer.rst
|