Basic Shapes
An ellipse for visualization. |
|
A line (or line segment) in 2D space. |
|
A rectangle for visualization. |
|
Alias of |
|
Alias of |
|
Alias of |
|
Alias of |
Ellipse
- class viren2d.Ellipse
An ellipse for visualization.
An ellipse is defined by its center point (
cxandcy), length of itsmajor_axis, length of itsminor_axisand it’s clockwiserotation(in degrees). At 0° rotation, the major axis is aligned with the \(x\) axis.Optionally, an ellipse can be drawn only partially, i.e. starting at
angle_from, drawing clockwise (with increasing angles) untilangle_to. For such partially drawn ellipses, you should consider adding the center point to the drawn path viainclude_center(which is the default behavior).For convenience, an ellipse can be implicitly created from a
listor atuple:>>> # Explicit initialization: >>> ellipse = viren2d.Ellipse(center, axes, ...) >>> # Implicitly cast from tuple: >>> painter.draw_ellipse((center, axes, ...), line_style=...)
Corresponding C++ API:
viren2d::Ellipse.The code listing to create this visualization is shown in the RTD tutorial section on ellipses.
Methods:
Checks for equality.
Overloaded function.
Checks for inequality.
Ellipseinstances can be pickled.Returns a deep copy.
Returns an ellipse defined by the endpoints of its major axis.
Returns
Trueif the ellipse can be drawn.Attributes:
Drawing the contour/filling starts at this angle (clockwise in degrees).
Drawing the contour/filling stops at this angle (clockwise in degrees).
Provides convenience access to the axes (i.e.
major_axisandminor_axis) as 2D vector, i.e.(major, minor).Provides convenience access to the center position (i.e.
cxandcy) as 2D vector.Horizontal center coordinate.
Vertical center coordinate.
If you explicitly change
angle_fromorangle_to, you very likely also want to include the center point in the rendered path.Length of the major axis.
Length of the minor axis.
Rotation angle (clockwise) in degrees.
- __eq__(self: viren2d.Ellipse, arg0: viren2d.Ellipse) bool
Checks for equality.
- __getstate__(self: viren2d.Ellipse) tuple
- __init__(*args, **kwargs)
Overloaded function.
__init__(self: viren2d.Ellipse, center: viren2d.Vec2d, axes: viren2d.Vec2d, rotation: float = 0.0, angle_from: float = 0.0, angle_to: float = 360.0, include_center: bool = True) -> None
Creates an ellipse.
- Parameters:
center – Center position as
Vec2d.axes – Lengths of the major and minor axes as
Vec2d. Order is(major, minor).rotation – Clockwise rotation angle in degrees as
float.angle_from – Starting angle in degrees as
float.angle_to – Ending angle in degrees as
float.include_center – If
Trueandangle_fromorangle_todiffer from their defaults, the center point will be included in the drawn/filled ellipse path (typebool).
__init__(self: viren2d.Ellipse, tpl: object) -> None
Creates an ellipse from a
tupleorlist.This overloaded constructor is required to allow implicit casting and supports 2 general tuple/list constellations:
A tuple/list holding
(center, size, rotation, angle_from, angle_to, include_center), wherecenter&sizeareVec2d,rotation,angle_fromandangle_toarefloatandinclude_centeris abool.A tuple/list holding
(cx, cy, major, minor, rotation, angle_from, angle_to, include_center), where all entries (except forinclude_center) arefloat.
In both cases,
rotation,angle_from,angle_toandinclude_centerare optional.
- __ne__(self: viren2d.Ellipse, arg0: viren2d.Ellipse) bool
Checks for inequality.
- __setstate__(self: viren2d.Ellipse, arg0: tuple) None
Ellipseinstances can be pickled.
- property angle_from
Drawing the contour/filling starts at this angle (clockwise in degrees).
Corresponding C++ API:
viren2d::Ellipse::angle_from.- Type:
- property angle_to
Drawing the contour/filling stops at this angle (clockwise in degrees).
Corresponding C++ API:
viren2d::Ellipse::angle_to.- Type:
- property axes
Provides convenience access to the axes (i.e.
major_axisandminor_axis) as 2D vector, i.e.(major, minor).Corresponding C++ API:
viren2d::Ellipse::Axes.- Type:
- property center
Provides convenience access to the center position (i.e.
cxandcy) as 2D vector.Corresponding C++ API:
viren2d::Ellipse::Center.- Type:
- copy(self: viren2d.Ellipse) viren2d.Ellipse
Returns a deep copy.
Corresponding C++ API: Copy constructor of
viren2d::Ellipse.
- static from_endpoints(pt1: viren2d.Vec2d, pt2: viren2d.Vec2d, width: float, angle_from: float = 0.0, angle_to: float = 360.0, include_center: bool = True) viren2d.Ellipse
Returns an ellipse defined by the endpoints of its major axis.
Assumes that the given coordinates specify the endpoints of the major axis.
Corresponding C++ API:
viren2d::Ellipse::FromEndpoints.- Parameters:
pt1 – First endpoint of the major axis as
Vec2d.pt2 – Second endpoint of the major axis as
Vec2d.width – Length of the minor axis as
float.angle_from – Starting angle in degrees as
float.angle_to – Ending angle in degrees as
float.include_center – If
Trueandangle_fromorangle_todiffer from their defaults, the center point will be included in the drawn/filled ellipse path (typebool).
- property include_center
If you explicitly change
angle_fromorangle_to, you very likely also want to include the center point in the rendered path. Otherwise, filling can easily lead to irritating results.Corresponding C++ API:
viren2d::Ellipse::include_center.- Type:
- is_valid(self: viren2d.Ellipse) bool
Returns
Trueif the ellipse can be drawn.Corresponding C++ API:
viren2d::Ellipse::IsValid.
- property major_axis
Length of the major axis.
Corresponding C++ API:
viren2d::Ellipse::major_axis.- Type:
- property minor_axis
Length of the minor axis.
Corresponding C++ API:
viren2d::Ellipse::minor_axis.- Type:
2D Line
- class viren2d.Line2d
A line (or line segment) in 2D space.
A line/segment is represented by two
Vec2d.Corresponding C++ API:
viren2d::Line2d.Methods:
Overloaded function.
Line2dinstances can be pickled.Returns the angle \(\alpha \in [0, 180]\) between this line and the second line.
Returns the angle \(\alpha \in [0, \pi]\) between this line and the second line.
Returns the angle \(\alpha \in [0, 180]\) between this line and the given directional vector.
Returns the angle \(\alpha \in [0, \pi]\) between this line and the given directional vector.
Clips this line against the given axis-aligned rectangle.
Clips this segment against the given axis-aligned rectangle.
Returns the closest point on the line, i.e. the projection of the given point onto this line.
Returns the closest point on this segment.
Returns the non-normalized direction vector from the start point to the end point.
Returns the minimum distance between the point and this line.
Returns the minimum distance between the point and this segment.
Returns the representation of this line in \(\mathbb{P}^2\).
Returns
Trueif the two lines are collinear.Returns
Trueif the two lines are parallel.Returns
Trueif the line is valid, i.e. \(\text{length} > 0\).Returns the interpolated point on the line/segment.
Returns a line/segment with flipped start/end points.
Tilts the segment around its start point.
Returns the unit direction vector from the start point to the end point.
Attributes:
Starting point.
End point.
- __getstate__(self: viren2d.Line2d) tuple
- __init__(*args, **kwargs)
Overloaded function.
__init__(self: viren2d.Line2d, pt1: viren2d.Vec2d, pt2: viren2d.Vec2d) -> None
Creates a line from 2 points.
__init__(self: viren2d.Line2d, tpl: tuple) -> None
Creates a line from a
tuple.This overloaded constructor is required to allow implicit casting from a tuple holding
(pt1, pt2),wherept1&pt2are the start and end pointsasVec2d.__init__(self: viren2d.Line2d, lst: list) -> None
Creates a line from a
list.This overloaded constructor is required to allow implicit casting from a list holding
[pt1, pt2],wherept1&pt2are the start and end pointsasVec2d.
- __setstate__(self: viren2d.Line2d, arg0: tuple) None
Line2dinstances can be pickled.
- angle_deg(self: viren2d.Line2d, other: viren2d.Line2d) float
Returns the angle \(\alpha \in [0, 180]\) between this line and the second line.
Corresponding C++ API:
viren2d::Line2d::AngleDeg.
- angle_rad(self: viren2d.Line2d, other: viren2d.Line2d) float
Returns the angle \(\alpha \in [0, \pi]\) between this line and the second line.
Corresponding C++ API:
viren2d::Line2d::AngleRad.
- angle_vec_deg(self: viren2d.Line2d, vec: viren2d.Vec2d) float
Returns the angle \(\alpha \in [0, 180]\) between this line and the given directional vector.
Corresponding C++ API:
viren2d::Line2d::AngleDeg.
- angle_vec_rad(self: viren2d.Line2d, vec: viren2d.Vec2d) float
Returns the angle \(\alpha \in [0, \pi]\) between this line and the given directional vector.
Corresponding C++ API:
viren2d::Line2d::AngleRad.
- clip_line_by_rectangle(self: viren2d.Line2d, top_left: viren2d.Vec2d, size: viren2d.Vec2d) viren2d.Line2d
Clips this line against the given axis-aligned rectangle.
Corresponding C++ API:
viren2d::Line2d::ClipLineByRectangle.- Parameters:
- Returns:
The clipped
Line2d. If the line did not intersect the rectangle, the result will be invalid. Check this viais_valid().
- clip_segment_by_rectangle(self: viren2d.Line2d, top_left: viren2d.Vec2d, size: viren2d.Vec2d) viren2d.Line2d
Clips this segment against the given axis-aligned rectangle.
Corresponding C++ API:
viren2d::Line2d::ClipLineSegmentByRectangle.- Parameters:
- Returns:
The clipped
Line2d. If the segment did not intersect the rectangle, the result will be invalid. Check this viais_valid().
- closest_point_on_line(self: viren2d.Line2d, point: viren2d.Vec2d) viren2d.Vec2d
Returns the closest point on the line, i.e. the projection of the given point onto this line.
Corresponding C++ API:
viren2d::Line2d::ClosestPointOnLine.
- closest_point_on_segment(self: viren2d.Line2d, point: viren2d.Vec2d) viren2d.Vec2d
Returns the closest point on this segment.
Corresponding C++ API:
viren2d::Line2d::ClosestPointOnSegment.
- direction(self: viren2d.Line2d) viren2d.Vec2d
Returns the non-normalized direction vector from the start point to the end point.
Corresponding C++ API:
viren2d::Line2d::Direction.
- distance_point_line(self: viren2d.Line2d, point: viren2d.Vec2d) float
Returns the minimum distance between the point and this line.
Corresponding C++ API:
viren2d::Line2d::DistancePointToLine.
- distance_point_segment(self: viren2d.Line2d, point: viren2d.Vec2d) float
Returns the minimum distance between the point and this segment.
Corresponding C++ API:
viren2d::Line2d::DistancePointToSegment.
- homogeneous(self: viren2d.Line2d) viren2d.Vec3d
Returns the representation of this line in \(\mathbb{P}^2\).
For more details on lines in projective space, refer to Bob Fisher’s CVonline, or Stan Birchfield’s lecture notes.
Corresponding C++ API:
viren2d::Line2d::HomogeneousForm.- Returns:
The
Vec3das the result of :math:` ext{pt1} imes ext{pt2}`.
- is_collinear(self: viren2d.Line2d, other: viren2d.Line2d) bool
Returns
Trueif the two lines are collinear.Corresponding C++ API:
viren2d::Line2d::IsCollinear.
- is_parallel(self: viren2d.Line2d, other: viren2d.Line2d) bool
Returns
Trueif the two lines are parallel.Corresponding C++ API:
viren2d::Line2d::IsParallel.
- is_valid(self: viren2d.Line2d) bool
Returns
Trueif the line is valid, i.e. \(\text{length} > 0\).Corresponding C++ API:
viren2d::Line2d::IsValid.
- left_to_right(self: viren2d.Line2d) viren2d.Line2d
Returns a line/segment where
pt1is left ofpt2.If this line is vertical, the points will be sorted such that the y coordinates are in ascending order.
Corresponding C++ API:
viren2d::Line2d::LeftToRight.
- property length
Length of the segment between
pt1andpt2.Corresponding C++ API:
viren2d::Line2d::Length.- Type:
- property mid_point
Mid point between
pt1andpt2.This property simply provides convenience access to the mid point. Alternatively, use
point_at_offset()for an adjustable offset along the line/segment.Corresponding C++ API:
viren2d::Line2d::MidPoint.- Type:
- point_at_offset(self: viren2d.Line2d, offset: float) viren2d.Vec2d
Returns the interpolated point on the line/segment.
Computes \(\text{pt}_1 + \text{offset} * (\text{pt}_2 - \text{pt}_1)\).
Corresponding C++ API:
viren2d::Line2d::PointAtOffset.
- property pt1
Starting point.
Corresponding C++ API:
viren2d::Line2d::Fromandviren2d::Line2d::SetFrom.- Type:
- property pt2
End point.
Corresponding C++ API:
viren2d::Line2d::Toandviren2d::Line2d::SetTo.- Type:
- reversed(self: viren2d.Line2d) viren2d.Line2d
Returns a line/segment with flipped start/end points.
Corresponding C++ API:
viren2d::Line2d::Reversed.
- tilt_deg(self: viren2d.Line2d, angle: float) viren2d.Line2d
Tilts the segment around its start point.
- unit_direction(self: viren2d.Line2d) viren2d.Vec2d
Returns the unit direction vector from the start point to the end point.
Corresponding C++ API:
viren2d::Line2d::UnitDirection.
Rectangle
Exemplary rectangle configurations:
The code listing to create this visualization is shown in the tutorial section on rectangles.
- class viren2d.Rect
A rectangle for visualization.
A rectangle is defined by its
center,width,height,rotation(clockwise, in degrees), and a cornerradius.For convenience, a rectangle can be implicitly created from a
listor atuple:>>> # Explicit initialization: >>> rect = viren2d.Rect(center, size, ...) >>> # Implicitly cast from tuple: >>> painter.draw_rect((center, size, ...), line_style=...)
Alternatively, an axis-aligned rectangle can also be initialized from the
L,T,W,HandL,R,T,Brepresentations:>>> # If top-left and dimensions are given: >>> rect = viren2d.Rect.rom_ltwh(left, top, width, height) >>> # If top-left and bottom-right corners are given: >>> rect = viren2d.Rect.rom_lrtb(left, right, top, bottom)
Corresponding C++ API:
viren2d::Rect.The code listing to create this visualization is shown in the RTD tutorial section on rectangles.
Methods:
Checks for equality.
Overloaded function.
Checks for inequality.
Rectinstances can be pickled.Returns a deep copy.
Returns a rectangle for the
Cx,Cy,W,Hrepresentation.Returns an axis-aligned rectangle for the
L,R,T,Brepresentation.Returns an axis-aligned rectangle for the
L,T,W,Hrepresentation.Returns
Trueif the rectangle can be drawn.Attributes:
Provides convenience access to the center position (i.e.
cxandcy) as 2D vector.Horizontal center coordinate.
Vertical center coordinate.
Half the rectangle height (read-only).
Half the rectangle width (read-only).
Rectangle height.
Corner radius.
Clockwise rotation angle in degrees.
Provides convenience access to the size (i.e.
widthandheight) as 2D vector.Rectangle width.
- __eq__(self: viren2d.Rect, arg0: viren2d.Rect) bool
Checks for equality.
- __getstate__(self: viren2d.Rect) tuple
- __init__(*args, **kwargs)
Overloaded function.
__init__(self: viren2d.Rect, tpl: object) -> None
Creates a rectangle from a
tupleorlist.This overloaded constructor is required to allow implicit casting and supports 2 general tuple/list constellations:
A tuple/list holding
(center, size, rotation, radius), wherecenter&sizeareVec2ds, androtation&radiusarefloat.A tuple/list holding
(cx, cy, w, h, rotation, radius), where all entries arefloat.
In both cases,
rotationandradiusare optional.__init__(self: viren2d.Rect, center: viren2d.Vec2d, size: viren2d.Vec2d, rotation: float = 0.0, radius: float = 0.0) -> None
Creates a rectangle.
- __ne__(self: viren2d.Rect, arg0: viren2d.Rect) bool
Checks for inequality.
- __setstate__(self: viren2d.Rect, arg0: tuple) None
Rectinstances can be pickled.
- property center
Provides convenience access to the center position (i.e.
cxandcy) as 2D vector.Corresponding C++ API:
viren2d::Rect::Size.- Type:
- copy(self: viren2d.Rect) viren2d.Rect
Returns a deep copy.
Corresponding C++ API: Copy constructor of
viren2d::Rect.
- static from_cwh(cx: float, cy: float, width: float, height: float, rotation: float = 0.0, radius: float = 0.0) viren2d.Rect
Returns a rectangle for the
Cx,Cy,W,Hrepresentation.Corresponding C++ API:
viren2d::Rect::FromCWH.- Parameters:
cx – Horizontal center coordinate as
float.cy – Vertical center coordinate as
float.width – Width (extent along the \(x\) axis if the rectangle is not rotated) as
float.height – Height (extent along the \(y\) axis if the rectangle is not rotated) as
float.rotation – Clockwise rotation in degrees as
float.radius – Corner radius as
float, see documentation of theradiusattribute.
- static from_lrtb(left: float, right: float, top: float, bottom: float, radius: float = 0.0) viren2d.Rect
Returns an axis-aligned rectangle for the
L,R,T,Brepresentation.Corresponding C++ API:
viren2d::Rect::FromLRTB.
- static from_ltwh(left: float, top: float, width: float, height: float, radius: float = 0.0) viren2d.Rect
Returns an axis-aligned rectangle for the
L,T,W,Hrepresentation.Corresponding C++ API:
viren2d::Rect::FromLTWH.
- property half_height
Half the rectangle height (read-only).
Corresponding C++ API:
viren2d::Rect::HalfHeight.- Type:
- property half_width
Half the rectangle width (read-only).
Corresponding C++ API:
viren2d::Rect::HalfWidth.- Type:
- is_valid(self: viren2d.Rect) bool
Returns
Trueif the rectangle can be drawn.Corresponding C++ API:
viren2d::Rect::IsValid.
- property radius
Corner radius.
If \(0 \leq \text{radius} \leq 0.5\), the actural corner radius will be computed as \(\text{radius} * \min(\text{width}, \text{height})\).
If \(\text{radius} > 1\), it denotes the absolute corner radius in pixels.
Otherwise, i.e. \(0.5 < \text{radius} < 1\), the rectangle will be invalid.
Corresponding C++ API:
viren2d::Rect::radius.- Type:
- property rotation
Clockwise rotation angle in degrees.
Corresponding C++ API:
viren2d::Rect::rotation.- Type:
Shape Utilitites
- viren2d.ellipse_from_endpoints(pt1: viren2d.Vec2d, pt2: viren2d.Vec2d, width: float, angle_from: float = 0.0, angle_to: float = 360.0, include_center: bool = True) viren2d.Ellipse
Alias of
viren2d.Ellipse.from_endpoints().
- viren2d.rect_from_cwh(cx: float, cy: float, width: float, height: float, rotation: float = 0.0, radius: float = 0.0) viren2d.Rect
Alias of
viren2d.Rect.from_cwh().
- viren2d.rect_from_lrtb(left: float, right: float, top: float, bottom: float, radius: float = 0.0) viren2d.Rect
Alias of
viren2d.Rect.from_lrtb().
- viren2d.rect_from_ltwh(left: float, top: float, width: float, height: float, radius: float = 0.0) viren2d.Rect
Alias of
viren2d.Rect.from_ltwh().

