Point¶
-
class
geometry.
Point
¶ Represents a 2D point in space, consisting of an x- and a y-coordinate
>>> Point(10, 20) (10, 20)
Vector is an alias for the Point type
>>> Vector(4, 5) (4, 5)
This class is implemented as a NamedTuple. This means:
You can use it like a tuple
>>> Point(4, 5)[0] 4
Its fields are named
>>> Point(4, 5).x 4 >>> Point(4, 5).y 5
It is immutable
>>> p = Point(4, 5) >>> p[0] = 0 Traceback (most recent call last): ... TypeError: 'Point' object does not support item assignment
Create new instance of Point(x, y)
-
x
¶ Alias for field number 0
-
y
¶ Alias for field number 1
-
__add__
(point: geometry.point.Point) → geometry.point.Point¶ Add two points component wise
>>> Point(10, 20) + Point(100, 200) (110, 220)
-
__sub__
(point: geometry.point.Point) → geometry.point.Point¶ Subtract two points component wise
>>> Point(10, 20) - Point(1, 2) (9, 18)
-
__mul__
(factor: Union[int, float]) → geometry.point.Point¶ Multiply a point with a factor
>>> Point(2, 3) * 4 (8, 12)
-
__rmul__
(factor: Union[int, float]) → geometry.point.Point¶ Multiply a point with a factor from the left
>>> 4 * Point(2, 3) (8, 12)
-
__floordiv__
(factor: Union[int, float]) → geometry.point.Point¶ Divide the components of a point by a factor (floor division)
>>> Point(2, 3) // 2 (1, 1)
-
__truediv__
(factor: Union[int, float]) → geometry.point.Point¶ Divide the components of a point by a factor
>>> Point(2, 3) / 2 (1.0, 1.5)
-
__matmul__
(other: geometry.point.Point) → Union[int, float]¶ Multiply two points (dot product)
>>> Point(1, 2) @ Point(2, 3) 8
-
__neg__
() → geometry.point.Point¶ Negate the components of a point
>>> -Point(1, 2) (-1, -2)
-
__abs__
() → Union[int, float]¶ The absolute value of a point: the length of the point
>>> abs(Point(3, 4)) 5.0
-
property
yx
¶ Transpose a point, i.e. flip x and y
>>> Point(1, 2).yx (2, 1)
-
property
length
¶ The length of the point
>>> Point(3, 4).length 5.0
-
property
normalized
¶ Return a copy of the point with the same direction but length 1.0
>>> Point(1, 1).normalized (0.707..., 0.707...)
-